Do you get any errors? Place some debug messages and see what happens. The best thing you can do is print the query that you run and try to run at the database.
public static void res(int m1)
{
String dataSourceName = "questions";
String dbURL = "jdbc:odbc:" + dataSourceName;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, "","");
String query = "INSERT INTO Final " +"(candidate, marks) "+" VALUES "+"(' "+ user +" ' , ' " +m1 +" ' )";
System.out.println("Query:>"+query+"<");
Statement s = con.createStatement();
int i = s.executeUpdate(query);
System.out.println("Rows updated: "+i);
//ResultSet ps = s.getResultSet();
System.out.println("Is it done??");
}
catch (Exception err)
{
err.printStackTrace();
System.out.println( "Error: " + err.getMessage() );
}
} // function ends
After you have made those changes to your code, here are your mistakes.
You don't close anything!!!! You must close whatever you open. In order to do that you need to close them in a finally block to make sure that they are always closed:
finally {
con.close();
s.close(); // the statement
}
But since those are declared inside the try the above code will not work because they are not visible outside it. Also the close operation also throws an exception so you need to put that in a try-catch as well:
public static void res(int m1)
{
String dataSourceName = "questions";
String dbURL = "jdbc:odbc:" + dataSourceName;
// Declared outside the try so they can be used inside the try and the finally
Connection con = null;
Statement …