Results 1 to 6 of 6

Thread: [RESOLVED] database with GUI

Threaded View

  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  

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