Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please, Why is my code not working?

 
Femi Ojambati
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All, Please, help me check this code

public Data class{
....
private static void new(){
PreparedStatement ps = conn.prepareStatement("INSERT INTO Members " +
"VALUES(?, ?, ?, ?)");
ps.setString(1, "14");
ps.setString(2, "Mike");
ps.setString(3, "Nwabikwo");
ps.setString(4, "14/10/2008");
ps.executeUpdate();
}

public static void main(String [] arg){

....
new();
}

}
Where conn is a Connection object that connects to JDBC-ODBC
When I tried to run it, I expect it to update the Database but it does not
and no exception is reported.
Please, tell me where the problem is.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to avoid the JDBC-ODBC bridge. It ha s bug that caches some statements so they don't actually get to the database.
To get the statement to run, either set autocommit(true) on the connection, or run a dummy select (ie a valid select operation, but you don't care about the result) on the dtaabase.
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the issue is not the connection (I have never seen the JDBC-ODBC bridge do that, BTW.). The issue is ps.executeUpdate

Try ps.execute();
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or maybe commiting the connection?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Femi Ojambati:
Hi All, Please, help me check this code

public Data class{
....
private static void new(){
PreparedStatement ps = conn.prepareStatement("INSERT INTO Members " +
"VALUES(?, ?, ?, ?)");
ps.setString(1, "14");
ps.setString(2, "Mike");
ps.setString(3, "Nwabikwo");
ps.setString(4, "14/10/2008");
ps.executeUpdate();
}

public static void main(String [] arg){

....
new();
}

}
Where conn is a Connection object that connects to JDBC-ODBC
When I tried to run it, I expect it to update the Database but it does not
and no exception is reported.
Please, tell me where the problem is.


try the query in this way:
1) INSERT INTO Members (columnName1, columnName2, columnName3, to_char(columnName4,'dd/mm/yyy') VALUES(?, ?, ?, ?)"

2) always close the connection and commit the record
ps.close();
cnn.commit();

Hope this will help to solve your problem

Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 50217
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Femi Ojambati:
....
new();
How do you get it to compile when you are using a keyword like that? Please look at this FAQ.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic