Ragazzi, mi sto impazzendo, devo popolare un database access formato da una chiave primaria username e un campo password, stoutilizzando netbeans per fare l'applicazione in jsp e java. Il bello è che a volte va tutto ok, ma spesso compare un generale error, il database è stato popolato ma risulta ancora aperto oppure a volte non viene neanche popolato. Il codice che utilizzo è il seguente:
codice:
private static void connect() throws SQLException{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e){
System.out.println("Impossibile caricare il driver: "+ e);
}
try{
//Connect to the database
con=DriverManager.getConnection(Constants.DB_CONNECTION_STRING, Constants.DB_USER_NAME, Constants.DB_PASSWORD);
con.setAutoCommit(false);
System.out.println("connessione riuscita al database");
}
catch(SQLException e){System.out.println(e);}
}
public static boolean addUser(String user, String pwd) throws SQLException{
connect();
stmt=con.createStatement();
String insSQL="INSERT INTO USERS VALUES ('"+user+"', '"+pwd+"')";
stmt.executeUpdate(insSQL);
con.commit();
stmt.close();
con.close();
return true;
}