Newbie Question JSP posting to MS-SQL DB

Discussion in 'Java' started by Mike, Sep 15, 2004.

  1. Mike

    Mike Guest

    I am new to Java. I have been trying some simple JSP connections to a
    MS-SQL table. I wrote one that reads from a test database and table
    that I set up and it works. I am now trying to write some simple code
    to use a form to fill in information and have this post to the table.
    Upon compile I get the following error:

    cannot resolve symbol symbol : variable Name
    location: class org.apache.jsp.testpost1_jsp
    ps.setString(1, Name);
    ^
    I also get the same error for my other ps.setString line.
    I know that I am connecting to the database, if I put " around the
    variables (ie. ps.setString(1, "Name");) it posts Name and Email to
    the database just fine. So my problem appears to be with my
    variables, but I am not sure what.
    I am just learning..

    Thanks in advance

    Here is my jsp:

    <%@ page contentType="text/html; charset=iso-8859-1" language="java"
    import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <TITLE> A JSP file for testing MSSQL database update</TITLE>
    </HEAD>
    <BODY>
    <jsp:useBean id='clock' scope='page' class='dates.JspCalendar'
    type="dates.JspCalendar" />
    <form action="" method=POST>
    Your Name <input type="text" name="Name"><BR>  
    Your Email <input type="text" name="Email"><BR>  
    <input type="hidden" name="Posted" value="1">
    <input type="submit" value="Sign Up">
    </form>
    <%
    // connecting to database
    Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
    Connection con = java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://XXX:1433;User=XXX;Password=XXX");
    PreparedStatement ps = con.prepareStatement("INSERT INTO
    XXX.dbo.MyUsers(Name, email) VALUES (?,?)");
    // inserting records
    ps.setString(1, Name);
    ps.setString(2, Email);
    ps.executeUpdate();
    %>
    </body>
    </html>
     
    Mike, Sep 15, 2004
    #1
    1. Advertising

  2. Andrew Thompson, Sep 16, 2004
    #2
    1. Advertising

  3. Mike

    Mike Guest

    That worked, thanks.

    Andrew Thompson <> wrote in message news:<>...
    > On 15 Sep 2004 12:12:26 -0700, Mike wrote:
    >
    > <%
    > String name = request.getParameter("Name");
    > String email = request.getParameter("Email");
    > %>
    >
    > ..
    > ps.setString(1, name);
     
    Mike, Sep 16, 2004
    #3
  4. On 16 Sep 2004 12:00:01 -0700, Mike wrote:

    > That worked, thanks.


    No worries.
     
    Andrew Thompson, Sep 16, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page