java - How to insert date or NULL to array -
i have following question. i'm using jdbc in project , made simple method insert data database.
my problem is: when want insert sysdate
or null
auto increment? method send strings , writing null
string doesn't work.
can give me advice how improve it?
this code constant null
in query, isn't want to.
public static void insertinto(string table, arraylist<string> values) throws sqlexception { connection conn = javaconnectdb.connectdb(); oraclepreparedstatement pst = null; stringbuilder query = new stringbuilder("insert " + table + " values (null, "); (int = 0; < values.size(); i++) { query.append("? "); if (i + 1 != values.size()) query.append(", "); } query.append(")"); pst = (oraclepreparedstatement) conn.preparestatement(query.tostring()); (int = 0; < values.size(); i++) { pst.setstring(i + 1, values.get(i)); } pst.executeupdate(); }
this method creates query "insert table values (null, ?, ? ,?)" , fills gaps values array.
there java.sql.preparedstatement.setnull(int, int)
try, e.g.
pst.setnull(1, types.bigint); (int = 1; < values.size(); i++) { pst.setstring(i + 1, values.get(i)); }
change types.bigint
apporpriate type column. note, values.get(0)
ignored, should present in array.
Comments
Post a Comment