views:

101

answers:

2
try {
    pst=con.prepareStatement("insert into stud values(?,?,?,?,?,?,?,?,?)");
    pst.setString(1,s1);
    pst.setString(2,s2);
    pst.setString(3,s3);
    pst.setString(4,s4);
    pst.setString(5,s5);
    pst.setString(6,s6);
    pst.setString(7,s7);
    pst.setString(8,s8);
    pst.setString(9,s9);
    int val=pst.executeUpdate();
    con.commit();
    con.close();
} catch(SQLException e) {
    System.out.println("except1");
}

This code gives the error "except1" which means it doesn't insert values in the database. Is something wrong with the SQL insert statement? The table stud is in the database.

+6  A: 

It's hard to say since you don't print any error information the exception object. There could be any number of problems, not even necessarily in this exact code snippet. You might have done something wrong earlier setting up the database connection, for example.

Change your println() to:

e.printStackTrace();

This will give you a lot more info to work with, including the error message from the database.

John Kugelman
A: 

It would help, to print the Exception-Code.

We can't find that special Problem. May be, yoou defined a column to be NOT-NULL and pass an Null-Value to the Statement. This may throw an Exception althoug the syntax is allright.

By the way, don't use System.out.println() or e.printStackTrace(). Use a Logger like java.util.Logging or log4j instead.

ckuetbach