code compilation problem,please help

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

  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:+Library";
    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,375
    Likes Received:
    388
    Trophy Points:
    83
    You had the same thread twice and both the time you had it in the wrong forum and as of now I have moved both to Java forum and closed the other thread.,
     
  3. rosesinspring

    rosesinspring New Member

    Joined:
    Jul 12, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Re: im sorry

    im really sorry..but please excuse me as im new to this site..and i hope to get an answer to my query in java :worried:
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice