0

hi,
im doing it in jsp and my backend is my sql ... im inserting the checkbox values and some details in table but for checkbox values i have given the executequery statement(where we write query) as integer so all other string details are not inserted in table it show "null" value in table...Pls any one help me..this is my coding..(only my seat1 to seat5 value are getting inserted)

<%@page import="java.sql.*, java.lang.String,Java.Util.*"%>
<%

   String TicketRate= request.getParameter("Ticket Rate");
   String ShowTime= request.getParameter("Show Time");
   String ShowDate= request.getParameter("Show Date");
   String NoOftickets= request.getParameter("No Of tickets");
   String Film= request.getParameter("Film");
   String checkValues[]=request.getParameterValues("vehicle");
	String value="";
	String valu="";
        String val="";
        String va="";
        String v="";
	String conURL="jdbc:mysql://localhost/cinema?";
	Class.forName("com.mysql.jdbc.Driver");
	Connection con=DriverManager.getConnection(conURL,"root","root");
	

for(int i=0;i<checkValues.length;i++)
{

   if(i==0)
   {
     value+=checkValues[0];
   }
   
   else if(i==1)
   {
     valu+=checkValues[1];
 
   } 


else if(i==2)
   {
     val+=checkValues[2];
 
   } 

else if(i==3)
   {
     va+=checkValues[3];
 
   } 

else 
{
v+=checkValues[4];
}  
}

Statement st=con.createStatement();
int j=st.executeUpdate("insert into seatings(TicketRate,ShowTime,ShowDate,NoOfTickets,Film,seat1,seat2,seat3,seat4,seat5) values('"+TicketRate+"','"+ShowTime+"','"+ShowDate+"','"+NoOftickets+"','"+Film+"','"+value+"','"+valu+"','"+val+"','"+va+"','"+v+"')");

out.println("Inserted successfully");

%>

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

2
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by mramkumar
0

1. Do not use JSP for communication with form. Pass data from JSP page to servlet and this should open connection to database and save data. You can find example here
2. Instead of using plain Statement have look on PreparedStatement (also used in previously linked tutorial)

0

HI,,
thanku for your reply i have corrected my mistake now its working fine..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.