A question for JSP/JDBC. Thx alot!

Hi all,

I am trying to do somework with JSP and JDBC. I want to save the current time/date to the database(MS access 2000) after a user finished fillup a form. I used the java.util.Date class to get the current time/date. Then use the method of java.util.Date.toString() to change the Date to String because the data type in the database is text. Then do updating the database. The server is Tomcat3.3. But the system always tells me that this is a problem with the "INSERT INTO" statement. But if I just insert other columns in the database, that is ok. I think it is strange.

The following is my code. I am wondering if there is another way to save the current time to the MS Access? Thanks alot!

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head><title></title></head>

<%@ page import = "java.sql.*" %>

<%! String connectionURL = "jdbc:odbc:Database"; %>

<%! String driverName = "sun.jdbc.odbc.JdbcOdbcDriver"; %>

<%

String title = request.getParameter("title");

String content = request.getParameter("content");

java.util.Date date = new java.util.Date();

String dateStr = date.toString();

Class.forName(driverName).newInstance();

Connection con = DriverManager.getConnection(connectionURL," "," ");

String insertStr = "INSERT INTO NEWS(Title, Content, Time) VALUES (?,?,?)";

PreparedStatement stmt = con.prepareStatement(insertStr);

stmt.setString(1, title);

stmt.setString(2, content);

stmt.setString(3, dateStr);

stmt.executeUpdate();

response.sendRedirect ("getTitle.jsp");

%>

<body>

<%=dateStr%>

</body>

</html>

<%

stmt.close();

con.close();

%>

[1873 byte] By [jiyuan_wang] at [2007-9-26 16:47:48]
# 1
That probably means the column in the database is not a text column, but a date/time column. If that is so, then do this instead:stmt.setTimestamp(3, date);
DrClap at 2007-7-2 20:43:14 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...