wood burning stoves 2.0*
The moose likes JDBC and the fly likes Please, Why is my code not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Please, Why is my code not working?" Watch "Please, Why is my code not working?" New topic
Author

Please, Why is my code not working?

Femi Ojambati
Greenhorn

Joined: Aug 13, 2008
Posts: 6
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Aug 17, 2006
Posts: 81
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

Joined: Oct 21, 2008
Posts: 1107

or maybe commiting the connection?
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
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

Joined: Oct 13, 2005
Posts: 38009
    
  22
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.
 
 
subject: Please, Why is my code not working?
 
Similar Threads
Adding code to return an ArrayList of objects
java.sql.DataTruncation: Data truncation
Batch Updates
Java Code does not recognize my sequence name
Prepared Statement problem in my servlet's data manager