This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

problem in database

 
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 ]
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • 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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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("jdbc:odbc: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
 
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("jdbc:odbc: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 ]
 
Ranch Hand
Posts: 1512
  • 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 ]
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic