I am having issues inserting data into a Database using a servlet.
My code is:
// receiving parameters
String strUserID = req.getParameter("txtUserID").trim();
String strUserTypeID = req.getParameter("txtUserTypeID").trim();
//int txtUserId = Integer(strUserID);
//int txtUserTypeID = Integer(strUserTypeID);
String comments = req.getParameter("notes").trim();
boolean proceed = false;
if(strUserID != null && strUserTypeID != null && comments != null)
if(comments.length() > 0)
proceed = true;
// connecting to database
Connection con = null;
Statement stmt = null;
PreparedStatement ps = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(dBURL);
//making the connection
String sql = "Insert Into tblUserNotepad(userID, userTypeID,
comments)
(?,?,?)";
ps = con.prepareStatement(sql);
stmt = con.createStatement();
if(proceed) {
ps.setString(1, strUserID);
ps.setString(2, strUserTypeID);
ps.setString(3, comments);
ps.executeUpdate();
}
out.print("<h1>Error 1 </h1>");
} catch (SQLException e) {
out.print("<h1>Error 2 </h1>");
throw new ServletException(e);
} catch (ClassNotFoundException e) {
out.print("<h1>Error 3 </h1>");
throw new ServletException(e);
} finally {
try {
if(stmt != null)
stmt.close();
if(ps != null)
ps.close();
if(con != null)
con.close();
} catch (SQLException e) {}
}
out.print("</body></html>");
out.close();
}
I get returned a "The page cannot be displayed" error.
1) How can I debug this?
2) How can I make this work?
Thanks one more time.
MTB
______________________________________________________________________
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists