Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in database  RSS feed

 
pradeepa sakthi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
Anyone can help me?How can i store selected item in data base.
if i select item from dropdown box to store database using jsp there is no items stored in database..if i use textfield it will stored..
how it is possible?
[ December 27, 2008: Message edited by: pradeepa sakthi ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in jsp:

<select name="drop_down">
<option value="-1">----------select---------</option>
<option value="42">pradeepa</option>
</select>

then you submit to servlet

in servlet:

String dropDownValue = request.getParameter("drop_down");

then store this value into DB

Hope this helps
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "jsp" in a forum completely dedicated to questions on JSP isn't very helpful.

Please go back and change your post to add a more meaningful subject by clicking the .
 
pradeepa sakthi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank for your response.but there is no data stored in DATABASE.
Here My Html code is:
<select name="S2">

<option selected="selected">Computer</option>
<input type="submit" name="Submit" value="Submit">
</form>

My Jsp Code is:

<%@ page import="java.sql.*"%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbcdbc:epdsn");
String Depar=request.getParameter("S2");
if(Depar.equals("Computer"))
{
PreparedStatement ps=con.prepareStatement("insert into computer values(?)");
ps.setString(1,Depar);
ps.executeUpdate();
%>
<%
}

%>
Hope you understand this problem.kindly give me response.thankyou
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't assign any value to the option. See the 1st reply on this topic.

I would follow a HTML tutorial as well. Also learning about servlets and the DAO pattern isn't a bad idea.
 
pradeepa sakthi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.i think not necessary to put option values in it.but it works.i had put data values not into the form.Tht's why the action couldn't be performed.now it works well.


How can i store radio button value into database.
My HTML code :
<form action="reg.jsp">

<input name="R1" type="radio" value="radiobutton" checked>
Male
<input name="R2" type="radio" value="radiobutton">
Female

<input type="submit" name="Submit" value="Submit">

</form>

Jsp Code:

<%@ page import="java.sql.*"%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbcdbc:hdsn");if((R1==Checked)&& equals("Male"))
{
String Sex=request.getParameter("R1");
else
{
String Sex=request.getParameter("R2");
PreparedStatement ps=con.prepareStatement("insert into computer values(?)");
ps.setString(1,Sex);
ps.executeUpdate();
%>
<%
}
}
%>
when i compile my code..it should displayed
Syntax: "}" inserted to complete StatementNoShortIf

ERROR..

i don't know..whether it is Misplaced Parenthesis in my code..
please help me.how can i store Radio button value into database..
Thanks in advance.

[ December 27, 2008: Message edited by: pradeepa sakthi ]
[ December 27, 2008: Message edited by: pradeepa sakthi ]
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is much easier to spot this kind of basic errors by just viewing the code if you wrote Java code in a clean and well-indented way in a real Java class (a servlet or a DAO class) rather than in a lousy scriptlet in a JSP. Exactly as I suggested before.
[ December 27, 2008: Message edited by: Bauke Scholtz ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to look into refactoring all this data access code to the backend (search for MVC) . Using a DAO would even be better. Also let a Servlet handle the processing of the request. Having it all as part of your JSP just makes it difficult to read.

PS. It does not help any that I am reading this from my smartphone.
[ December 27, 2008: Message edited by: Bosun Bello ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!