Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Newbie Question JSP posting to MS-SQL DB

Reply
Thread Tools

Newbie Question JSP posting to MS-SQL DB

 
 
Mike
Guest
Posts: n/a
 
      09-15-2004
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:microso ft: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>
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      09-15-2004
On 15 Sep 2004 12:12:26 -0700, Mike wrote:

<%
String name = request.getParameter("Name");
String email = request.getParameter("Email");
%>

...
ps.setString(1, name);

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      09-16-2004
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);

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-16-2004
On 16 Sep 2004 12:00:01 -0700, Mike wrote:

> That worked, thanks.


No worries.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP newbie - <jsp:useBean > question zalek Java 1 08-23-2008 07:19 PM
JSP newbie - can I use JSP to access exiting java classes withoutre-write to javabeans terry433iid@yahoo.com Java 2 03-17-2008 01:40 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
Top Posting vs. Bottom Posting scaredkitty Computer Support 37 04-06-2005 12:27 AM
Everytime I hover cursro over a posting, it crosses out with red mark on it.. on every posting alanb ASP .Net 2 04-23-2004 02:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57