a java student
May 8th, 2008, 08:19 PM
In the beginning part of the doGet, I initialized a String variable "insertSQL" to "" and an Integer variable "rows" to 0. Then in the try catch block, I
assigned "insertSQL" to hold an insert statement and "rows" to hold the
the number of rows inserted. At the end, I debugged these two variables.
The "insertSQL" is "" and "rows" is 0. It looks like that the try catch block was skipped. Can anyone help please? Thanks.
====================================================
public void doGet(HttpServletRequest request,
HttpServletResponse response
throws IOException, ServletException
{
String url = "jdbc:odbc:RegistrationForm";
String userID = "anonymous";
String passWord = "guest";
String insertSQL ="";
int rows =0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(url,
userID, passWord);
insertSQL = "INSERT INTO RegistrationForm ( FirstName)
VALUES ( 'John')";
statement = connection.createStatement();
rows = statement.executeUpdate(insertSQL);
statement.close();
connection.close();
}
catch (ClassNotFoundException cnfe)
{ cnfe.printStackTrace(); }
catch (SQLException sqle)
{ sqle.printStackTrace(); }
catch (Exception e)
{ e.printStackTrace(); }
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head><title>Registration
Confirmation</title></head>");
pw.println("<body>");
pw.println("<h2>Thank You for Registration</h2>");
pw.println("DEBUG insertSQL="+insertSQL);
pw.println("DEBUG rows="+rows);
pw.println("</body>");
pw.println("</html>");
}
assigned "insertSQL" to hold an insert statement and "rows" to hold the
the number of rows inserted. At the end, I debugged these two variables.
The "insertSQL" is "" and "rows" is 0. It looks like that the try catch block was skipped. Can anyone help please? Thanks.
====================================================
public void doGet(HttpServletRequest request,
HttpServletResponse response
throws IOException, ServletException
{
String url = "jdbc:odbc:RegistrationForm";
String userID = "anonymous";
String passWord = "guest";
String insertSQL ="";
int rows =0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(url,
userID, passWord);
insertSQL = "INSERT INTO RegistrationForm ( FirstName)
VALUES ( 'John')";
statement = connection.createStatement();
rows = statement.executeUpdate(insertSQL);
statement.close();
connection.close();
}
catch (ClassNotFoundException cnfe)
{ cnfe.printStackTrace(); }
catch (SQLException sqle)
{ sqle.printStackTrace(); }
catch (Exception e)
{ e.printStackTrace(); }
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head><title>Registration
Confirmation</title></head>");
pw.println("<body>");
pw.println("<h2>Thank You for Registration</h2>");
pw.println("DEBUG insertSQL="+insertSQL);
pw.println("DEBUG rows="+rows);
pw.println("</body>");
pw.println("</html>");
}