I want to create a java jar file.Which can find data from mysql.i've made it possible to find data from mysql from my java prgrame.but when i make a jar file then it cant find the data.how can i solve this problem.plese help me.its urgent.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I want to create a java jar file.Which can find data from mysql.i've made it possible to find data from mysql from my java prgrame.but when i make a jar file then it cant find the data.how can i solve this problem.plese help me.its urgent.
What do you mean 'can't find the data'? Do you get exceptions? You need to describe your problem in more detail
tnkx for response.my problem is that when i create a jar file then when i execute the jar then it doesnt work.i mean doesnt search & insert into mysql databases.I use netBean ide.but in my netBean editor it works properly.please help me.
"It doesn't work" provides no information to answer your question. No one knows your code, the exceptions, how you are running, and even what you are doing (search and insert can mean many different things). Once again I will ask to describe your problem in more detail...code, exceptions etc...wild guess - place the drive on your classpath. Also...suggested reading: How to ask questions
my code is bellow
I have inserted data into the databases previously .this programe is to search those data it runs fine.thats ok.but when i create a executable jar file it cant search the data from databases.i used mysql databases.import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; import java.util.*; public class test extends JFrame { public static void main(String kl[]) { test t=new test(); t.setVisible(true); } public test() { initComponents(); } private void button1ActionPerformed() { try{ Vector heading = new Vector(); heading.addElement("name"); heading.addElement("roll"); heading.addElement("Dept"); try{ Vector data = new Vector(); Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection(dbdriver,dbuser,dbpass); sta=conn.createStatement(); rs= sta.executeQuery("select * from sd"); while(rs.next()) { name = rs.getString("Name"); roll = rs.getString("Roll"); dept = rs.getString("Dept"); //create a row Vector tmp = new Vector(); tmp.addElement(name); tmp.addElement(roll); tmp.addElement(dept); //add to model data.addElement(tmp); } table1 = new JTable(data,heading); } catch (Exception ep) {} }catch (Exception ep) {} scrollPane1.setViewportView(table1); scrollPane1.setVisible(true); } private void initComponents() { scrollPane1 = new JScrollPane(); //table1 = new JTable(); button1 = new JButton(); //======== this ======== Container contentPane = getContentPane(); contentPane.setLayout(null); //======== scrollPane1 ======== { scrollPane1.setVisible(false); //scrollPane1.setViewportView(table1); } contentPane.add(scrollPane1); scrollPane1.setBounds(155, 105, 320, 80); //---- button1 ---- button1.setText("OK"); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button1ActionPerformed(); } }); contentPane.add(button1); button1.setBounds(new Rectangle(new Point(325, 320), button1.getPreferredSize())); { // compute preferred size Dimension preferredSize = new Dimension(); for(int i = 0; i < contentPane.getComponentCount(); i++) { Rectangle bounds = contentPane.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); } Insets insets = contentPane.getInsets(); preferredSize.width += insets.right; preferredSize.height += insets.bottom; contentPane.setMinimumSize(preferredSize); contentPane.setPreferredSize(preferredSize); } pack(); setLocationRelativeTo(getOwner()); } private JScrollPane scrollPane1; private JTable table1; private JButton button1; String dbdriver="jdbc:mysql://localhost:3306/test"; String dbuser="root"; String dbpass="123"; Connection conn; Statement sta; ResultSet rs,rs1; String name,roll,dept; }
please help me.tnkx for suggesting.
Hey
I feel you haven't put sql connector in to your jar file.
or you can put the reference of the sql connector in the Manifest
You don't need to copy the class files from another jar file into your applications jar file. You can reference the other jar file by putting an entry in the manifest file for your jar file.
For example here is a contents of a manifest file:
Code:
Main-Class: GetURLText
Class-Path: DocumentViewerWParser.jar
I have both jar files in the same folder when I execute my app:
java -jar <jarfile>
Another way is to use a script to start the app with both jar files specified on the classpath:
Code:
java -cp <yourjarile>:<otherjarfile> <classname
Refrence from : Create .jar file for java code using jdbc-mysql on eclipse - Ubuntu Forums
thanks to Dan Brown and Copeg for reply.It is solved now.