Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  
 

error:Parameter index out of range (1 > number of parameters, which is 0).

Ads

 
 

Share on Google+Share on Google+

akanksha
error:Parameter index out of range (1 > number of parameters, which is 0).
2 Answer(s)      4 years and 5 months ago
Posted in : JSP-Servlet

my code:String org=request.getParameter("Org"); String desg=request.getParameter("des"); String From=request.getParameter("From"); String To=request.getParameter("To"); String expdetail=request.getParameter("expdetail"); System.out.println(org); String sqlOption1="Insert into experience(candidateid,org,desg,from,to,expdetail) select * from candidate where candidateid in(select max(candidateid) from candidate)"; String sqlOption2="select candidateid from candidate"; ps1=conn.prepareStatement(sqlOption1); rs=ps1.executeQuery(sqlOption2); System.out.println(ps1); while(rs.next()) { c=rs.getString("candidateid"); } System.out.println(c); ps1.setString(1,c); ps1.setString(2,org); ps1.setString(3,desg); ps1.setString(4,From); ps1.setString(5,To); ps1.setString(6,expdetail); int x=ps1.executeUpdate();

Ads
View Answers

March 7, 2013 at 4:03 PM


hi friend,

You are using PreparedStatement to insert the value. And you are trying to set the value of field using the setXXXX() method of PreparedStatement and in your SQL string you didn't use the ? (question mark) to assign a value. So edit your sql string as follows:

Edit your sql string as INSERT INTO table_name VALUES (?,?,?,?). Number of question mark should be equal to the number of fields in table.

Thanks.



March 7, 2013 at 4:18 PM


you are missing a matching escape

Insert into experience(candidateid,org,desg,from,to,expdetail) select * from candidate where candidateid in(select max(candidateid) from candidate)";

It should be like this

Insert into experience('candidateid', 'org', 'desg', 'from', 'to','expdetail') select * from candidate where candidateid in(select max('candidateid') from candidate)";


Ads









Related Tutorials/Questions & Answers:
error:Parameter index out of range (1 > number of parameters, which is 0).
error:Parameter index out of range (1 > number of parameters, which is 0...: Edit your sql string as INSERT INTO table_name VALUES (?,?,?,?). Number of question mark should be equal to the number of fields in table. Thanks.   
Index Out of Bound Exception
is thrown when  a String  object detects an index  out-of-range index. Usually, An string object occurs out-of-range , when the index is less than zero... Index Out of Bound Exception   
Advertisements
write an application that print out the even numbers between the range 100-200
write an application that print out the even numbers between the range 100-200   write an application that print out the even numbers between the range 100-200 ?   The given code accepts the number from 100 to 200
MySQL range
MySQL range       May times the programmer needs to find out some specific data which lies in the particular range of values but there is not any predefined function in MySQL but we
In and Out parameters - SQL
parameters-IN,OUT,INOUT. 1)IN: It is default parameter which is passed...In and Out parameters  What are in and out parameters in stored...)OUT: This parameter does not supply any value to the procedure.It is assumed
How do I find out the number of parameters passed into function9. ?
How do I find out the number of parameters passed into function9. ?  How do I find out the number of parameters passed into function9
Find out the prime number
Find out the prime number      ... to find out whether a given number is prime or not. Here we have used the 'for loop..., a prime number is only divided by 1 and itself, in other words it has no other
supplying values to in parameters of stored procedure in ms sql and displaying out parameters
supplying values to in parameters of stored procedure in ms sql and displaying out parameters  I have to execute following procedure ALTER PROCEDURE [dbo].[get_date] @codeId int, @vardate as datetime OUTPUT AS SELECT
What is Index?
What is Index?  What is Index
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer not divisible by 7 and 5 ? 2- Number of the numbers which are not divisible
Prime Numbers from range
)); while (i>1){ if ((number!=i) && (number%i==0...(); int index1=0; int index2=number.length()-1; char x...; if (index2-index1==0 || index2-index1==1) list.add(i); index1
range of int in c
range of int in c  What is the range of int in c/c++ and Java programming language
date range in sql
date range in sql  How can I select a random date from a date range in SQL server
Which request executed first Out of multiple requests in servlet
Which request executed first Out of multiple requests in servlet  Servlet handles multiple request simultaneously.Every new request will be assigned... to servlet ,which request will be executed first , please correct me if question
find out in servlet which button was clicked on an html page
find out in servlet which button was clicked on an html page  i have two buttons on my jsp page... and i want two call two seperate codes in a servlet on pressing of those 2 buttons.. how do i find out which button was clicked so
Mysql Btree Index
Mysql Btree Index  Mysql BTree Index Which tree is implemented to btree index? (Binary tree or Bplus tree or Bminus tree
Drop Index
_table(stu_id); Drop Index THE drop index stu_index 1 is used... Drop Index       Drop Index is used to remove one or more indexes from the current database
index of javaprogram
index of javaprogram  what is the step of learning java. i am not asking syllabus am i am asking the step of program to teach a pesonal student.   To learn java, please visit the following link: Java Tutorial
range of dates in mysql query
range of dates in mysql query  How to select the range of dates in mysql ..when i have to select from between & and of date function?   SELECT * FROM MAAccounts WHERE updatedOn BETWEEN ? AND ? ORDER
the number of parameters
the number of parameters  How do I find out the number of parameters passed into function
What is the byte range? - Java Beginners
What is the byte range?   Hi, Please tell me range in byte. Thanks   The range is: 128 to 127 Thanks
NSMutableArray change object at Index
to replace object, it's the best way to do that) for (int index = 0; index <...NSMutableArray change object at Index   NSMutableArray change object at Index   // Browse all messages (you can use "for (NSDictionary
i am confused here on what to write can some 1 help out here - Java Beginners
i am confused here on what to write can some 1 help out here  i don't quite understand how to code it so can some one help out
Generating random numbers in a range with Java
Generating random numbers in a range with Java  Generating random numbers in a range with Java
really need help on how to write this program plz some 1 help out. - Java Beginners
really need help on how to write this program plz some 1 help out.  i am confused here on what to write can some 1 help out here i dont quite understand how to code it so can some 1 help out. Part II Write, compile and execute
clustered and a non-clustered index?
clustered and a non-clustered index?  What is the difference between clustered and a non-clustered index
Java arraylist index() Function
Java arrayList has index for each added element. This index starts from 0. arrayList values can be retrieved by the get(index) method. Example of Java Arraylist Index() Function import
Version of com.albertoquesada>multi-range dependency
List of Version of com.albertoquesada>multi-range dependency
JavaScript array index of
line. 1)index of( )  - This return the position of the value that is hold...JavaScript array index of  In this Tutorial we want to describe that makes you to easy to understand JavaScript array index of. We are using JavaScript
About Dr. Karni Singh Shooting Range Delhi
enjoy in this part of the range. This outdoor range is laid out over a large...The Dr. Karni Singh Shooting Range in Delhi Most people who travel to Delhi may not think that a shooting range is a worthwhile attraction. However