954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to save int and string in exucutequery statement

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");

%>
mramkumar
Newbie Poster
3 posts since Oct 2010
Reputation Points: 10
Solved Threads: 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)

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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

mramkumar
Newbie Poster
3 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: