Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 9th, 2007, 07: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

  #2 (permalink)  
Old December 21st, 2007, 03: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
  #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)
  #4 (permalink)  
Old January 29th, 2013, 07: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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass vector values form one JSP midhun JSP Basics 1 January 30th, 2006 06: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 05:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.