Adding Timestamp Value in MS Access DB (MDB) using java JDBC -
i trying insert new row in table has timestamp column value. following code:
long millisecs = system.currenttimemillis() ; timestamp ts = new java.sql.timestamp(millisecs) ; s.executeupdate("insert tblpublichols(date) values("+ts+")");
i tried preparedstatment follows:
long millisecs = system.currenttimemillis() ; timestamp ts = new java.sql.timestamp(millisecs) ; preparedstatement pstmt ; pstmt = conn.preparestatement("insert tblbasicholiday " + "(date, regionid) " + "values (?, ?)") ; pstmt.clearparameters() ; pstmt.settimestamp(1, ts); pstmt.setint(2, 1); int count = 0 ; count = pstmt.executeupdate() ;
still getting same error, follows
java.sql.sqlexception: [microsoft][odbc microsoft access driver] syntax error in insert statement.
can me out on this? thanks.
i suspect problem date
reserved word. try:
string sql = "insert tblbasicholiday ([date], regionid) values (?, ?)"; preparedstatement pstmt = conn.preparestatement(sql);
(note should closing statement in finally
block, too.)
Comments
Post a Comment