File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Can someone debug this code, I'm stumped... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Can someone debug this code, I Watch "Can someone debug this code, I New topic

Can someone debug this code, I'm stumped...

David Yutzy
tumbleweed and gunslinger
Ranch Hand

Joined: Jun 29, 2001
Posts: 192
This code executes without exception, but the record does not get inserted. The oV object is a validation bean I'm using and I've output the get... values and they are valid.
Also, the oManager.oCon is my connection pool manager and it is returning a valid connection object as I can navigate around using the same bean/connection and other queries work fine.
I'm using mySQL as DB. No issues there (other queries work fine).
Any ideas?
public void insertArticle(Validation oV) throws Exception {
PreparedStatement oStmt = null;
String SQL = "";

try {
SQL = "insert into LatestNews (Article, PostDate, NewsHeader) values (?, ?, ?)";

Debug = SQL;

oStmt = oManager.oCon.prepareStatement(SQL);

//oStmt.setInt(1, Integer.parseInt(oV.getUserID()));
oStmt.setString(1, oV.getArticle());
oStmt.setString(2, oV.getPostDate());
oStmt.setString(3, oV.getNewsHeader());

} catch (Exception e) {
throw new Exception("
" + oName + ": insertArticle(" + oV.getArticle() + ", " + oV.getPostDate() + ", " + oV.getNewsHeader() + "): " + e);
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Is the date passed in as a String?
>> oStmt.setString(2, oV.getPostDate());
Might be that.

Terry Doyle
Sun Certified Programmer for Java 2 Platform

Raising Flares debut album 'Ignition' out now

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
David Yutzy
tumbleweed and gunslinger
Ranch Hand

Joined: Jun 29, 2001
Posts: 192
I found the issue...It appears that I can only insert records if the date format is yyyy-mm-dd. If you pass a date into mySQL as mm/dd/yyyy, it doesn't insert the record and doesn't throw any exceptions...
Anyone else have this kinda issue?
It is sorta covered in the JavaRanch Style Guide.
subject: Can someone debug this code, I'm stumped...