Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 9th, 2007, 06:13 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default JSP code to insert values from HTML form to SQL se

Hi Guyz,
Can some one post a JSP code to insert values
from an HTML Form to a SQL server table.
Am using Apache tomcat. am a new to jsp.
I will be glad.
u can send the Code can be sent to byamlinux@yahoo.com

Reply With Quote
  #2 (permalink)  
Old December 21st, 2007, 02:32 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ironchef
Default

easy peasy. Ok, so suppose your form has a field - 'txtFirstName'. Here is the code you might use to enter that persons first name into the 'UserInfo' table using mysql.



...tagblibs for core and sql standard libraries...

<sql:update dataSource="...datasource for sql table">
INSERT INTO UserInfo (firstName) VALUES (?)
<sql:param value="${param.txtFirstName}" />
</sql:param>

<c:redirect url="success.jsp" />

:D

IronChef - http://www.freewebs.com/cool_recipes
Reply With Quote
  #3 (permalink)  
Old April 19th, 2011, 11:21 AM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default PLEASE HELP WITH JSP /mysql

.<%
String connectionURL = "jdbc:mysql://localhost:3306/xxx";
Class.forName("com.mysql.jdbc.Driver").newInstance ();
java.sql.Connection connection = java.sql.DriverManager.getConnection(connectionURL , "xxxx", "xxxx");

String strSQL_Select = "SELECT * FROM user WHERE username = '"+request.getParameter("username")+"'";

java.sql.Statement statement = connection.createStatement();

java.sql.ResultSet RS = statement.executeQuery(strSQL_Select);

int i = 0;
while (RS.next())
{
i++;
}

if (i == 0)
{

String query = "INSERT INTO user (username,password,address1,address2,city,postcode ,number,name,surname,email) VALUES (?,?,?,?,?,?,?,?,?,?)"; java.sql.PreparedStatement statement = connection.prepareStatement(query);
statement.setString(1,request.getParameter("userna me"));
statement.setString(2,request.getParameter("passwo rd"));
statement.setString(3,request.getParameter("addres s1"));
statement.setString(4,request.getParameter("addres s2"));
statement.setString(5,request.getParameter("city") );
statement.setString(6,request.getParameter("postco de"));
statement.setString(7,request.getParameter("number "));
statement.setString(8,request.getParameter("name") );
statement.setString(9,request.getParameter("surnam e"));
statement.setString(10,request.getParameter("email "));
statement.executeUpdate();

}
else
{
out.println("Username has been used!"); }

connection.close();
%>

----------------------------------------------------
I get an error

The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 74 in the jsp file: /ProcessInsertUser1.jsp Duplicate local variable statement
71: {
72:
73: String query = "INSERT INTO user (username,password,address1,address2,city,postcode ,number,name,surname,email) VALUES (?,?,?,?,?,?,?,?,?,?)";
74: java.sql.PreparedStatement statement = connection.prepareStatement(query);
75: statement.setString(1,request.getParameter("userna me"));
76: statement.setString(2,request.getParameter("passwo rd"));
77: statement.setString(3,request.getParameter("addres s1"));


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:93)
org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:319)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:298)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:286)
org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
Reply With Quote
  #4 (permalink)  
Old January 29th, 2013, 06:42 AM
Authorized User
Points: 359, Level: 6
Points: 359, Level: 6 Points: 359, Level: 6 Points: 359, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: Belgrade, Serbia, Yugoslavia.
Posts: 73
Thanks: 11
Thanked 1 Time in 1 Post
Wink sabra

How to coding PHP 5 width JavaScript
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass vector values form one JSP midhun JSP Basics 1 January 30th, 2006 05:49 PM
JSP form values to Oracle table (Insert) gokul_blr JSP Basics 1 August 17th, 2004 12:59 AM
Access HTML form values in a VB DLL madhukp Pro VB 6 2 July 25th, 2004 11:58 PM
Can't display values of HTML form controls hosefo81 Beginning PHP 3 November 10th, 2003 04:34 AM



All times are GMT -4. The time now is 06:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.