views:

83

answers:

2

I am new to jdbc and i'm try to connect to by database form IDE.The code below is what i wrote;

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {
        DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
        Connection conn=DriverManager.getConnection("jdbc:derby://localhost:1527/sample","app","app");
        preparedStatement ps=conn.prepareStatement("select name,zip,discount_code from customer where customer_id=?");
        ps.setInt(1,Interger.parseInt(jTextField1.getText()));
        ResultSet rs=ps.executeQuery();
        if(rs.next()) {
            jTextField2.setText(rs.getString(1));
            jTextField3.setText(rs.getString(2));
            jComboBox1.setSelectedItem(rs.getString(3));
        }                                        
    } catch (NumberFormatException ex) {
        ex.PrintStackTrace();
    }catch (SQLException ex){
        ex.printStackTrace();
    }
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jdfrm().setVisible(true));
            }
        }
    }

The error is..class "frm1.jdfrm" does not have a main method

+1  A: 

your main form is inside the private void jButton1ActionPerformed.. check the parenthesis

lorenzog
Though why does a nested method compile? That's certainly odd.
Francis Upton
because you can have a 'main' method in every class. If you want to execute it, though, it needs to be in a public class and it has to be visible.
lorenzog
@Francis - did it really compile **without errors**? Some IDEs compile as much as possible, inserting an Error throw (Unresolved compilation problem) at the error point.
Carlos Heuberger
@Carlos, yes, Eclipse inserts the runtime error, but it also shows the compile error. Don't know about other IDEs though.
Francis Upton
A: 

Your brackets look like they are not right. You need another closing before the main method.

Francis Upton