Results 1 to 6 of 6

Thread: [RESOLVED] database with GUI

  1. #1

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Resolved [RESOLVED] database with GUI

    hi all,
    please someone help me, i'm got stuck in a problem. i'm getting weird output. below is my code, and i'm getting output having blocks with data displayed in textboxes..
    plz take a look and tell me what i'm doing wrong,

    **db.java**
    Code:
    import java.sql.*;
    
    class db
    {
    Statement st;
    Connection con;
    ResultSet rs;
    
    public db()
    {
    connect();
    }
    public void connect()
    {
    	try{
    	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    	String url="jdbc:odbc:data1";
    	con=DriverManager.getConnection(url);
    	st=con.createStatement();
    	String sql="select * from Table1";
    	rs=st.executeQuery(sql);
    	
    	/*while(rs.next())
    	{
    		String name=rs.getString("fname");
    		String lname=rs.getString("lname");
    		System.out.println(name+" "+lname);
    	
    	}*/
    	//con.close();
    	
    	}
    	catch(Exception ex)
    	{
    		System.out.println(ex);
    	}
    }
    
    public static void main(String args[])
    {
    	new db();
    	new GUI();
    }
    
    }
    **gui.java**

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    class GUI extends db
    {
    	JFrame f;
    	JTextField t1;
    	JTextField t2;
    	JLabel l1;
    	JLabel l2;
    	
    	public void inGUI()
    	{
    		f=new JFrame();
    		Container c=f.getContentPane();
    		c.setLayout(new FlowLayout());
    		l1=new JLabel("First name");
    		t1=new JTextField(10);
    		l2=new JLabel("Second name");
    		t2=new JTextField(10);
    		c.add(l1);
    		c.add(t1);
    		c.add(l2);
    		c.add(t2);
    		
    		f.setSize(400,400);
    		f.setVisible(true);
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		try{
    		rs.next();
    		t1.setText(rs.getString("fname"));
    		t2.setText(rs.getString("lname"));
    		}
    		catch(Exception ex)
    		{
    			System.out.println(ex);
    		}
    	}
    	public GUI()
    	{
    		inGUI();
    	}
    	public static void main(String args[])
    	{
    		new GUI();
    	
    	}
    
    
    
    
    }
    Attached Images Attached Images  

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: database with GUI

    Looks like a problem with the character set. Is the data saved in the database in unicode format? Also check the language settings of the database and of the computer which is running the app.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Re: database with GUI

    Quote Originally Posted by honeybee View Post
    Looks like a problem with the character set. Is the data saved in the database in unicode format? Also check the language settings of the database and of the computer which is running the app.

    .
    thanks for replying

    i'm using MS Access 2010 and then i saved the table with 2003 format. I've set the datatype as text for all field, can you tell me if i'm wrong?
    any help would be appreciated.

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: database with GUI

    Can you try saving the table in 2010 format? Does 2003 support unicode?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: database with GUI

    Can you post the contents of that table ?

    Is it like this:
    Code:
    
    First Name  |  Last Name
    ------------------------
    Ali | Khan
    aash | Vbforums
    ....
    
    Does it contain anything else after the name ? Any spaces ?

    Also, try these:
    Code:
    t1.setText(rs.getString("fname").trim());
    t2.setText(rs.getString("lname").trim());
    I don't have Java installed in my PC right now. So, what I am posting is all just my assumptions.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  6. #6

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Re: database with GUI

    Quote Originally Posted by akhileshbc View Post
    Can you post the contents of that table ?

    Is it like this:
    Code:
    
    First Name  |  Last Name
    ------------------------
    Ali | Khan
    aash | Vbforums
    ....
    
    Does it contain anything else after the name ? Any spaces ?

    Also, try these:
    Code:
    t1.setText(rs.getString("fname").trim());
    t2.setText(rs.getString("lname").trim());
    I don't have Java installed in my PC right now. So, what I am posting is all just my assumptions.

    wow, you're awesome. The trim() has solved my problem,
    thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width