inserting data into a table using jsp & jdbc
843835Apr 8 2002 — edited Apr 8 2002Hi,
Can someone pls help me in there:
i 've written some jsp codes to get information from a form and then insert these info into a table:
but the info is not being inserted into my table..i think its a problem with the SQL syntax(JDBC).
there is the code
<%@ page import="java.sql.*,"%>
<%
Connection conn= null;
Statement stmt = null;
ResultSet results = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Data";
conn = DriverManager.getConnection(url," "," ");
out.write("Connection Successful");
String id = request.getParameter("txtitemid");
out.write(id);// shows that the id has been captured
stmt = conn.createStatement();
stmt.executeUpdate(
"INSERT INTO PRODUCTS Item_id,Desc,Price,Qty_available" +
"VALUES (id,'TEST SUCCESSFUL', 7.99,6)");
conn.close();
}
catch (ClassNotFoundException e) {
System.err.println("Could not connect to the database!");
}
catch (SQLException e) {
System.err.println("Could not connect to the database!");
}
finally {
try { if(conn!=null) conn.close();}
catch (SQLException e) { }
}
%>
<html>
<table>
<tr><td>Item number</td><td>
<jsp:getproperty="item" property="id"/></td></tr>
<tr><td>Description</td><td>
<jsp:getproperty="item" property="desc"/></td></tr>
<tr><td>Price $</td><td>
<jsp:getproperty="item" property="price"/></td></tr>
<tr><td>On Hand</td><td>
<jsp:getproperty="item" property="stock"/></td></tr>
</table>
</body>
</html>
can somebody pls help
thanks