Hi guys, this problem makes no sense. This code compiles, runs with no errors, returns that 1 record was updated, yet the database remains unchanged. No setxxx commands work. Autocommit is on. The database is Access 2002, and wonder if that might be a problem. Can anyone else run this or similar simple setxxx using access database? Database is called dbtest registered with ODBC, table is employees, has at least two rows and a column called emp_id. code: import java.sql.*; import java.io.*;
public class test { static Driver d; static Connection conn; final static String jdbcDriver="sun.jdbc.odbc.JdbcOdbcDriver"; static String databaseURL = "jdbc:odbc:" + "dbtest"; public static void main(String[] args) { try { d = (Driver) Class.forName(jdbcDriver).newInstance(); conn = DriverManager.getConnection(databaseURL);
PreparedStatement stmt = conn.prepareStatement( "UPDATE employee SET emp_id = ? WHERE Index = ?"); stmt.setString( 1, "John" ); stmt.setInt( 2, 2); System.out.println("about to update"); int count = stmt.executeUpdate(); System.out.println("number updated=" + count); } catch( Exception e ){ System.out.println("Error:" + e); } }}
Thank you in advance for any advice or results. JJ
Ha! beat you to it! I am answering my own problem, after a week of intense frustration, I desperately plugged in a conn.close() statement and it now works. I had left it up to the java cleanup crew, and they didn't do the job!
ResultSet rs1 = smt.executeQuery("update Emplye set age = 45 where Nom = 'TOTO'") ; rs1.updateInt("Age",45) ; rs1.updateRow() ;
//PreparedStatement psmt = conX.prepareStatement("update Emplye set age = 45 where Nom = 'TOTO'",ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE) ; //psmt.executeUpdate() ;
} catch(SQLException ex0){ System.out.println(" Update ne marche pas ") ; }
System.out.println(" J'ai fini d'executer update ") ;