Insert Java.sql.Date into Derby Database -
i trying insert date object database says im trying insert integer. here code:
public void insertassignment(long studentid, string newassignment, int ptstotal, int ptsrecieved, string category, date duedate, string term, int yr) { java.sql.date temp = new java.sql.date(duedate.gettime()); try{ s.execute("insert assignments " + "values (" + studentid + ",'" + newassignment + "'," + ptstotal + "," + ptsrecieved + ",'" + category + "'," + temp + ",'" + term + "'," + yr + ")"); system.out.println("assignment inserted."); } catch(sqlexception error){ system.err.println("unable insertassignment."); error.printstacktrace(system.err); system.exit(0); } }
my error: java.sql.sqlsyntaxerrorexception: columns of type 'date' cannot hold values of type 'integer'.
to this, use prepared statement instead , use setter.
currently flatten date string value (which needs in right format database work) , lose date database needs parse it. avoid using prepared statement.
Comments
Post a Comment