I'm a neewbie in this
help what's wrong with this one..

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.sql.*" %>

<%
        //create a Connection, Statement, and ResultSet object to connect to the database
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

        String queryText = "insert into PetInfo Pet Name, Pet Type, Pet Gender, Pet Price values('";
        queryText = queryText.concat(request.getParameter("petName"));
        queryText = queryText.concat("','");
        queryText = queryText.concat(request.getParameter("petType"));
        queryText = queryText.concat("','");
        queryText = queryText.concat(request.getParameter("gender"));
        queryText = queryText.concat("','");
        queryText = queryText.concat(request.getParameter("price"));
        queryText = queryText.concat("')");

       try {
            //initialize the JDBC-ODBC bridge driver
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection("jdbc:odbc:pets");

        //now insert a record into the database
            //execute the query
      stmt = con.createStatement();
      rs = stmt.executeQuery(queryText);
    } catch (Exception e) {}
%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>


<table width="100%" cellpadding="5">
  <tr valign="top"> 
    <td> 
      <table width="100%" cellpadding="5" bgcolor="#FFFFFF" border="1" cellspacing="0">
        <tr> 
          <td> 
            <h1>Add to the database</h1>
            <p>The following entry was added to the database:</p>

            <table border="0" cellspacing="0" cellpadding="5">
              <tr> 
                <td> 
                  <div align="right">Pet name:</div>
                </td>
                <td><b><%= request.getParameter("petName") %></b> </td>
              </tr>
              <tr> 
                <td> 
                  <div align="right">Pet TYpe:</div>
                </td>
                <td><b><%= request.getParameter("petType") %></b> </td>
              </tr>
              <tr> 
                <td> 
                  <div align="right">Pet Gender:</div>
                </td>
                <td><b><%= request.getParameter("gender") %></b> </td>
              </tr>
              <tr> 
                <td> 
                  <div align="right">Pet Price:</div>
                </td>
                <td><b><%= request.getParameter("price") %></b> </td>
              </tr>
            </table>
            <p><a href="dataEntry.html">Return to main page</a> and add more to the database 
              for the entry you just added.</p>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.