Hi, I am new to database connectivity using servlets. I have a form which on clicked should insert data into database. I am able to get the data from the fields as follows: String HLDY_CODE = req.getParameter("HOLIDAY_CODE").trim(); String HLDY_DESCR = req.getParameter("HOLIDAY_DESCR").trim(); String HLDY_DATE = req.getParameter("HOLIDAY_DATE").trim(); String USERID = req.getParameter("LST_CHANGE_USERID").trim(); I am trying to insert these into the database. I tried the following way but its not working. String sql = "INSERT into hldy(HLDY_CODE, HLIDY_DESCR"; sql += ", HLIDY_DATE, USERID, TIME_STAMP) values (?, ?, ?, ?, ?)"; ps = conn.prepareStatement(sql); stmt = conn.createStatement(); //inserting records ps.setString(1, HOLIDAY_CODE); ps.setString(2, HOLIDAY_DESCR); ps.setString(3, HOLIDAY_DATE); ps.setString(4, LAST_CHANGE_USERID); I also need to insert the time stamp when the record is being inserted. The fields of "hldy" table are HLDY_CODE, HLDY_DESCR, HLDY_DATE, USERID, TIME_STAMP. How can I find the time the record is being inserted?? Can someone point me in the right direction please. Thanks Chak
Manjunath Reddy
Ranch Hand
Joined: Jul 26, 2001
Posts: 60
posted
0
try this...and im assuming you are successfull in getting a connection to the database through your driver manager. String sql = "INSERT into hldy(HLDY_CODE, HLIDY_DESCR"; sql += ", HLIDY_DATE, USERID, TIME_STAMP) values (?, ?, ?, ?, ?)"; ps = conn.prepareStatement(sql); //stmt = conn.createStatement();(what was this doing here ???)
//depends on limitations of database timestamp storage types Timestamp tsDateTime = new Timestamp(new Date().getTime()); //inserting records ps.setString(1, HOLIDAY_CODE); ps.setString(2, HOLIDAY_DESCR); ps.setString(3, HOLIDAY_DATE); ps.setString(4, LAST_CHANGE_USERID); ps.setString(5, tsDateTime ); int iInsertCount = pStmt.executeUpdate(); cheers, mpr
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.