The Artima Developer Community
Sponsored Link

Java Answers Forum
preparedstatement not working! help!

2 replies on 1 page. Most recent reply: Jun 11, 2002 4:37 PM by KOUASSI AKA

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Jenny

Posts: 2
Nickname: jj
Registered: Apr, 2002

preparedstatement not working! help! Posted: Apr 30, 2002 10:30 AM
Reply to this message Reply
Advertisement
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


Jenny

Posts: 2
Nickname: jj
Registered: Apr, 2002

Re: preparedstatement not working! help! Posted: Apr 30, 2002 10:48 AM
Reply to this message Reply
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!

JJ

KOUASSI AKA

Posts: 1
Nickname: fifi
Registered: Jun, 2002

Re: preparedstatement not working! help! Posted: Jun 11, 2002 4:37 PM
Reply to this message Reply
Jenny, can you help me , I have the same pb with an access db.



import java.io.* ;
import java.sql.* ;


public class Test{

public static void main(String args[]){

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance() ;

Connection conX = DriverManager.getConnection("jdbc:odbc:LIENTEST","","") ;

Statement smt = conX.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE) ;

try{

System.out.println(" Je vais executer update ") ;

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 ") ;


ResultSet rs = smt.executeQuery("select * from Employe") ;
while(rs.next()){
System.out.println(" "+rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3)+" "+rs.getDouble(4)) ;
}

System.out.println(" Operation realisee avec suscces ") ;

}
catch(SQLException ex0){

System.out.println(" Pas bon 1") ;
}

catch(ClassNotFoundException ex1){

System.out.println(" Pas bon 2") ;
}

catch(InstantiationException ex2){

System.out.println(" Pas bon ") ;
}
catch(IllegalAccessException ex2){

System.out.println(" Pas bon ") ;
}





}

Flat View: This topic has 2 replies on 1 page
Topic: exit function in frames Previous Topic   Next Topic Topic: novice question about threads: AccessControlException?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use