• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

insertion of checkbox values from jsp to database

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai any one can help regarding this.

iam involved in e-ticketing project..

iam going to retrieve ticket values from database to jsp page. Now i want to book the ticket so i will select the ticket using checkbox..the selected ticket value should be insert into mysql db..i tried to insert but its not inserting can anyone help me..
my code is here below :


<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>�

<html>
<head>
<title>display data from the table using jsp</title>
</head>
<body>
<h2 align="center"></h2>
<select id="cbosex" name="cbosex">
<option value="true">Male</option>
<option value="false">Female</option>
</option>

<%
try {

Connection con = null;
Statement st= null;
ResultSet rs = null;


Class.forName("org.gjt.mm.mysql.Driver");
con=DriverManager.getConnection("jdbc:mysql://192.168.1.201:3306/e_busticketing","root","password");
st = con.createStatement();
out.println("connected");
String sql="select seat_no from e_busticketing.seat_mast where bus_id=1001";
rs=st.executeQuery(sql);

%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;" width=20% align="center">
<%
while (rs.next()) {
%>
<TR>
<TD><INPUT TYPE=CHECKBOX NAME=c1 value=<%=rs.getString("seat_no")%> ></TD>

</TR>
<% } %>
<%
// close all the connections.
rs.close();
st.close();
con.close();

}
catch (Exception ex)
{
%>
</font>

<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%>
</TABLE><TABLE align="center">
<TR>
<TD><FORM ACTION="busdetail.jsp" method="get" >
<button type="submit"><-- back</button></TD>
</TR>
</TABLE>
</font>

<%
/*
try
{
Class.forName("org.gjt.mm.mysql.Driver");
con=DriverManager.getConnection("jdbc:mysql://192.168.1.201:3306/e_busticketing","root","password");
out.println("connected sucessfully");

Statement st = con.createStatement();
int numRowsChanged = st.executeUpdate("insert into e_busticketing.seat_details(seat) values (c1)";

out.println("data inserted");

}



catch (Exception e)
{
e.printStackTrace();
}
}
}
*/
%>
</body>
</html>
regards
gopi
[ November 11, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What error are you getting when you do the insert or it's just not inserting?

You should probably refactor your code and move all that database logic to the backend and call the backend via a servlet. Search for MVC for more info.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your Logic is quite fuzzy
As said by earlier respondent please move all JDBC related code to some Controller or some Business Layer

Please don't open connections in jsp.

You can't handle exceptions in elegant way here

Besides this,move our actions event oriented Like on clicking of some button pass the values from jsp to some servlet and there insert values appropriately
 
gopi sri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you friends,

i will do that...
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic