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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -