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.

Results 1 to 7 of 7

Thread: i cant make a java jar file which can search data from mysql

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default i cant make a java jar file which can search data from mysql

    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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,302
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: i cant make a java jar file which can search data from mysql

    What do you mean 'can't find the data'? Do you get exceptions? You need to describe your problem in more detail

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: i cant make a java jar file which can search data from mysql

    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.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,302
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: i cant make a java jar file which can search data from mysql

    "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

  5. #5
    Junior Member
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: i cant make a java jar file which can search data from mysql

    my code is bellow

    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;
     
    }
    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.
    please help me.tnkx for suggesting.

  6. #6
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: i cant make a java jar file which can search data from mysql

    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 and Regards
    Dan Brown

    Common Java Mistakes

  7. #7
    Junior Member
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i cant make a java jar file which can search data from mysql

    thanks to Dan Brown and Copeg for reply.It is solved now.

Similar Threads

  1. saving data in persian language in mysql db
    By java_cs in forum JDBC & Databases
    Replies: 2
    Last Post: January 19th, 2011, 11:26 AM
  2. [SOLVED] Passing data to a MySQL database
    By JDyson in forum JDBC & Databases
    Replies: 1
    Last Post: December 1st, 2010, 12:31 PM
  3. [ask]input data from java file to another java
    By bontet in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: October 29th, 2010, 10:50 AM
  4. [SOLVED] Get Data From Database MySQL using ComboBox
    By Simple in forum Java Theory & Questions
    Replies: 2
    Last Post: June 4th, 2010, 02:45 AM