This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Error while inserting readings1java.sql.SQLException: Missing IN or OUT parameter at index:: 1
Satish Nair
Greenhorn
Joined: Apr 04, 2012
Posts: 23
posted
0
Dear All,
I am writing a code where i have data to insert in 4 different tables. hence i used 4 prepared statement.Kindly help as i am getting the above error when running the program through netbeans
E Armitage
Ranch Hand
Joined: Mar 17, 2012
Posts: 220
posted
0
Did you set all the parameters on your PreparedStatement before executing the query?
The obvious errors in that code which will make it fail to compile lead me to believe that it isn't actually the code you're asking about. However:
This code suggests that your PreparedStatement (based on the query you didn't show us) has at least 24 parameters, and you're only setting 3 of them. You have to set all 24, or however many there are.
As Paul says, this surely can't be your actual code. But if it is, then you also have problems with your variable name for the aprMS parameter, as well as the missing parenthesis
String aprms=request.getParameter("aprMS")==null)? new String():request.getParameter("aprMS");
...
pst1.setString(4,aprMS);
Maybe post the real code so people can see what you are really doing?
//String tankQuery="select * from tankmaster where roid="+roId+" and PRODUCTID in("+strPrd+")";
//String pumpQuery="select dispno,pumpid,nozzleid from dispenser_master where roid="+roId+" and productid in("+strPrd+") and flag='Y' order by NOZZLEID";
try
{
//String res="";
//out.println("tanktestdt");
//boolean flag = new Boolean(false);
//String strUpdateFlag = "";
//if(tFlag )
//out.println("true");
//Connection conn2=null;
try
{
//conn.setAutoCommit(false);
conn=getCon();
String insrtStmt1="insert into CROSSLNK.QUARTER1TARGETDATA(aprMS,aprHSD,aprAlpg,aprLubes,aprTyres,aprRcare_Tyres,aprRcare_Lubes,aprRcare_spares,aprRcare_service,aprAFS,mayMS,mayHSD,mayAlpg,mayLubes,mayTyres,mayRcare_Tyres,mayRcare_Lubes,mayRcare_spares,mayRcare_service,mayAFS,junMS,junHSD,junAlpg,junLubes,junTyres,junRcare_Tyres,junRcare_Lubes,junRcare_spares,junRcare_service,junAFS) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pst1 =conn.prepareStatement(insrtStmt1);
int updateQuery;
{
String aprMS = (request.getParameter("aprMS")==null)? new String():request.getParameter("aprMS");
String aprHSD = (request.getParameter("aprHSD")==null)? new String():request.getParameter("aprHSD");
String aprAlpg = (request.getParameter("aprAlpg")==null)? new String ():request.getParameter("aprAlpg");
String aprLubes = (request.getParameter("aprLubes")==null)? new String ():request.getParameter("aprLubes");
String aprTyres = (request.getParameter("aprTyres")==null)? new String ():request.getParameter("aprTyres");
String aprRcare_Tyres = (request.getParameter("aprRcare_Tyres")==null)? new String ():request.getParameter("aprRcare_Tyres");
String aprRcare_Lubes = (request.getParameter("aprRcare_Lubes")==null)? new String ():request.getParameter("aprRcare_Lubes");
String aprRcare_spares = (request.getParameter("aprRcare_spares")==null)? new String():request.getParameter("aprRcare_spares");
String aprRcare_service = (request.getParameter("aprRcare_service")==null)? new String ():request.getParameter("aprRcare_service");
String aprAFS = (request.getParameter("aprAFS")==null)? new String():request.getParameter("aprAFS");
String mayMS = (request.getParameter("mayMS")==null)? new String():request.getParameter("mayMS");
String mayHSD = (request.getParameter("mayHSD")==null)? new String():request.getParameter("mayHSD");
String mayAlpg = (request.getParameter("mayAlpg")==null)? new String ():request.getParameter("mayAlpg");
String mayLubes = (request.getParameter("mayLubes")==null)? new String ():request.getParameter("mayLubes");
String mayTyres = (request.getParameter("mayTyres")==null)? new String ():request.getParameter("mayTyres");
String mayRcare_Tyres = (request.getParameter("mayRcare_Tyres")==null)? new String ():request.getParameter("mayRcare_Tyres");
String mayRcare_Lubes = (request.getParameter("mayRcare_Lubes")==null)? new String ():request.getParameter("mayRcare_Lubes");
String mayRcare_spares = (request.getParameter("mayRcare_spares")==null)? new String():request.getParameter("mayRcare_spares");
String mayRcare_service = (request.getParameter("mayRcare_service")==null)? new String ():request.getParameter("mayRcare_service");
String mayAFS = (request.getParameter("mayAFS")==null)? new String():request.getParameter("mayAFS");
String junMS = (request.getParameter("junMS")==null)? new String():request.getParameter("junMS");
String junHSD = (request.getParameter("junHSD")==null)? new String():request.getParameter("junHSD");
String junAlpg = (request.getParameter("junAlpg")==null)? new String():request.getParameter("junAlpg");
String junLubes = (request.getParameter("junLubes")==null)? new String():request.getParameter("junLubes");
String junTyres = (request.getParameter("junTyres")==null)? new String():request.getParameter("junTyres");
String junRcare_Tyres = (request.getParameter("junRcare_Tyres")==null)? new String():request.getParameter("junRcare_Tyres");
String junRcare_Lubes = (request.getParameter("junRcare_Lubes")==null)? new String():request.getParameter("junRcare_Lubes");
String junRcare_spares = (request.getParameter("junRcare_spares")==null)? new String():request.getParameter("junRcare_spares");
String junRcare_service = (request.getParameter("junRcare_service")==null)? new String():request.getParameter("junRcare_service");
String junAFS = (request.getParameter("junAFS")==null)? new String():request.getParameter("junAFS");
Paul Clapham wrote:This code suggests that your PreparedStatement (based on the query you didn't show us) has at least 24 parameters, and you're only setting 3 of them. You have to set all 24, or however many there are.
And did you check that code to see if you were indeed setting all of the parameters? The error message said you weren't, so I would have thought you would have already checked your code rather than just dumping it here.
Satish Nair
Greenhorn
Joined: Apr 04, 2012
Posts: 23
posted
0
It would be greatful if you could help me on where i am going wrong
Oh boy. I should have suggested you post the relevant real code here, instead of dumping all this on us.
I can't make much sense of all that stuff, but a superficial look suggests that you are not setting the first few parameters in your INSERT.
As far as I can tell, you have 30 parameters for your INSERT statement, but you set them from number 4 to 33:
I'm no JDBC expert, but I suspect that might have something to do with the "Missing parameter at index 1..." error message.
You have other problems with this code as well, but my weekend really is too short to trawl through it all.
Just a thought, but it looks like your data could be modeled more easily something like this (assuming the targets are numeric e.g. sales or units), which would make the SQL and Java much easier and probably give you more flexibility in using the data, but I guess that depends on who is responsible for your data model and whether it's already finalised.
Note: There are underscores in all the column names etc, but you can't see them in the "code" view above.
E Armitage
Ranch Hand
Joined: Mar 17, 2012
Posts: 220
posted
1
Please do yourself a favour and realize that this path is a really dark and dangerous one. No one should have to any of those things you are doing in your code these days.
Pick an MVC framework that allows you to automatically bind those values to POJOs and preferably a persistence strategy that builds the data manipulation statements automatically from the POJOs.
Also, remove the data access logic from the JSP. Use JSPs to present information only.