File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 1106

or maybe commiting the connection?
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
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: 36453
    
  15
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.
 
Consider Paul's rocket mass heater.
 
subject: Please, Why is my code not working?
 
Similar Threads
Batch Updates
Java Code does not recognize my sequence name
Prepared Statement problem in my servlet's data manager
Adding code to return an ArrayList of objects
java.sql.DataTruncation: Data truncation