Newbie Question JSP posting to MS-SQL DB

M

Mike

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top