Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / May 2007

Tip: Looking for answers? Try searching our database.

Need Help : taking data from JSP page and putting in MySQL database

Thread view: 
tomtumelty@gmail.com - 11 May 2007 18:49 GMT
I am using Sun JDK 1.5.0_09, Tomcat 5.5.17, MySQL 5.0 .

I am gathering data from a webpage using jsp. Beans are handling the
database operations. I have tested the Bean code and it correctly adds
data to the database table.

For some reason the data entered in the jsp page is not entered in the
database. I suspect the error is in the jsp (..maybe....)???? Any
suggestions ?

Or another thought, maybe an initialization problem? should the
variables chainName, address1, address2, city, state, zipCode,
phoneNumber  be initialized to an empty string in the bean that stores
the data  like this :

String chainName="";
String address1="";
String address2="";
String city="";
String state="";
String zipCode="";
String phoneNumber="";

Thanks in advance.

******************************************************************
jsp page is below :

<jsp:useBean id="ChainInfoBean" class="com.bean.ChainInfoBean"
scope="request"/>

<jsp:useBean id="GiftData" class="com.bean.dataBase" scope="session" /

<jsp:setProperty name="ChainInfoBean" property="*"/>

<html>
<head><title>Add Chain</title></head>
<body bgcolor="white">

<h2>Chain Information</h2>
<form ACTION="../gift/AddChain.jsp" method=POST>

<P>
Chain Name <input type="text" name="chainName" value="" size=50
maxlength=50>
<P>
Address 1 <input type="text" name="address1" value="" size=50
maxlength=50>
<P>
Address 2 <input type="text" name="address2" value="" size=50
maxlength=50>
<P>
City <input type="text" name="city" value="" size=50 maxlength=50>
<P>
State <input type="text" name="state" value="" size=2 maxlength=2>
<P>
Zipcode <input type="text" name="zipCode" value="" size=9 maxlength=9>
<P>
Phone Number <input type="text" name="phoneNumber" value="" size=10
maxlength=10>
<p></p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>

<%
if (request.getMethod().equals("POST") ) {
out.println("POST");

String [] results;
// String ResponseCode;

GiftData.init();

results = GiftData.addChain("E",
                       ChainInfoBean.getchainName(),
                ChainInfoBean.getaddress1(),
                ChainInfoBean.getaddress2(),
                ChainInfoBean.getcity(),
                ChainInfoBean.getstate(),
                ChainInfoBean.getzipCode(),
                ChainInfoBean.getphoneNumber()
                );

}
%>

</body>
</html
Philipp Taprogge - 11 May 2007 21:14 GMT
Hi!

> For some reason the data entered in the jsp page is not entered in the
> database. I suspect the error is in the jsp (..maybe....)???? Any
> suggestions ?

Hmm... perhaps I am missing something here, but you don't seem to
include any code that would store the data into the db. This is not
done automagically for a plain old webapp. You would have to create
and execute SQL statements yourself to store the fields.
For example, you could have multiple jsps with fields and a submit
button leading to the "next" jsp. Each page would add it's fields to
the bean data. But in the end, after the last submit, you would
still have to put all that stuff into the DB.
You could either do it in a jsp or, more cleanly, write a servlet to
handle the SQL and have it redirect to a jsp after it's done.
Retrieval of a DataSource would be done through JNDI, but there are
enough good tutorials for that out there.

Another approach to that same problem would be a so-called
object-relational mapper like Hibernate that would do the SQL-stuff
for you, but that might be overkill for what you are aiming at.

HTH,

    Phil
tomtumelty@gmail.com - 11 May 2007 22:30 GMT
> Hi!
>
[quoted text clipped - 24 lines]
>
>         Phil

The code that stores data in the database is written in stored
procedures and is called from a JavaBean. There are two beans, one
stores data and has the  get and set methods. The other bean handles
the database connection and database manipulation. JDBC Mysql/
Connector J is being used to connect to the database.  I should have
made this clear, thank you.

The problem seems to be getting the data from the jsp to the bean.
I keep looking at the JavaServer Pages O'Reilly book and googling but
not finding anything that helps yet.

Thak You very much.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.