Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

inserting data into a table using jsp & jdbc

843835Apr 8 2002 — edited Apr 8 2002
Hi,
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

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 6 2002
Added on Apr 8 2002
1 comment
350 views