1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

code compilation problem,please help

Discussion in 'Java' started by rosesinspring, Jul 12, 2008.

Thread Status:
Not open for further replies.
  1. rosesinspring

    rosesinspring New Member

    Joined:
    Jul 12, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    import java.awt.*;
    import java.sql.*;
    import java.awt.event.*;
    public class pubinfo implements ActionListener
    {
    Label lpubid;
    TextField pub_id;
    Button insert;
    Panel p1;
    Frame f1;
     Connection con;
    PreparedStatement stat;
    Statement stmt;
    ResultSet rs;
    public pubinfo()
    {
    try
    {
    	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    String url = "jdbc:odbc:+LifeLine2";
    Connection db_connection = DriverManager.getConnection (url, "sa", "friendship");
    Statement stmt = db_connection.createStatement();
    }
    catch (ClassNotFoundException cnfe) 
    {
    	System.err.println ("Unable to load database driver");
    	System.err.println ("Details : " + cnfe);
    	System.exit(0);
    }
    }
    public void display()
    {
    f1 =new Frame("pubinfo");
    p1 =new  Panel();
    lpubid =new Label("Login");
    pub_id=new TextField(6);
    insert =new Button("ok");
    
    lpubid.setBounds(250,35,200,40);
    pub_id.setBounds(100,90,100,25);
    p1.add(lpubid);
    p1.add(pub_id);
    
    insert.addActionListener(this);
    }
    
    
    public void actionPerformed(ActionEvent ae)
    {
    if(ae.getActionCommand() == "ok")
    {
    try
    {
    stat=con.prepareStatement("INSERT INTO pubinfo VALUES(?)");
    String pid=pub_id.getText();
    stat.setString(1,pid);
    stat.executeUpdate();
    pub_id.setText(" ");
    }
    
    catch(Exception e)
    {
    System.out.println(" Error1:" +e);
    error.SetText("row not inserted");
    }
    }
    }
    
    public static void main(String args[])
    {
    pubinfo p= new pubinfo();
    p.display();
    
    }
    }
     
    Last edited by a moderator: Jul 12, 2008
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page