File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Error while inserting readings1java.sql.SQLException: Missing IN or OUT parameter at index:: 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Error while inserting readings1java.sql.SQLException: Missing IN or OUT parameter at index:: 1 " Watch "Error while inserting readings1java.sql.SQLException: Missing IN or OUT parameter at index:: 1 " New topic
Author

Error while inserting readings1java.sql.SQLException: Missing IN or OUT parameter at index:: 1

Satish Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 23
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
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Did you set all the parameters on your PreparedStatement before executing the query?
Satish Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 23
this is what i did:


try
{
String query=insert into.....table 1

PreparedStatement pst1;
pst1 =conn.prepareStatement(query);

String aprms=request.getParameter("aprMS")==null)? new String():request.getParameter("aprMS");
String mayMS = (request.getParameter("mayMS")==null)? new String():request.getParameter("mayMS");
String junMS = (request.getParameter("junMS")==null)? new String():request.getParameter("junMS");

pst1.setString(4,aprMS);
pst1.setString(14,mayMS);
pst1.setString(24,junMS);

pst1.executeUpdate();
}
catch()
{
}
pst1.close();

try
{
PreparedStatement pst2;
String query2=insert into ......table 2

pst=conn.perpareStatement(query2);
String julMS = (request.getParameter("julMS")==null)? new String ():request.getParameter("julMS");
String augMS = (request.getParameter("augMS")==null)? new String ():request.getParameter("augMS");
String sepMS = (request.getParameter("sepMS")==null)? new String ():request.getParameter("sepMS");

pst2.setString(4,julMS);
pst2.setString(14,augMS);
pst2.setString(24,sepMS);

pst2.executeUpdate();
}
catch()
{
}
pst2.close();
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1726
    
  14

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?


No more Blub for me, thank you, Vicar.
Satish Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 23
Actual code is bit long.......

here it is:

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






<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<Title>Enter Target details</Title>



<script language="javascript">

function onlyNumbers(evt)
{
var e = event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57))
{

alert("Only numbers allowed");
return false;
}
else
return true;
}

function submitform()
{
document.forms["myform"].submit();
}

//{

//alert('submited');

function showMessage() {
alert ("Data updated successfully!");
return true;
}

function dodisable()
{
document.form1.text.disabled="true";
}







</script>

</head>
<%!
Connection getCon()
{
String driver_class = "oracle.jdbc.driver.OracleDriver";
String connectionURL = "jdbcracle:thin:@10.66.26.28:1521:retaildb";
String userID = "crosslnk";
String userPassword = "crosslnk";
java.sql.Connection conn = null;
try {
Class.forName(driver_class).newInstance();


conn = DriverManager.getConnection(connectionURL, userID, userPassword);



} catch(Exception ce) {
System.out.println("Error1 while obtaining connection: " + ce);
//e.printStackTrace();
}
return conn;
}


%>
<body class="CCStarterBody" marginwidth="0">
<form name="manualTargetEntryForm" method="GET" action="sat.jsp" onsubmit="return submitform(this)">
<%


java.sql.Connection conn = null;

java.sql.PreparedStatement pst1=null,pst2=null,pst3=null,pst4=null;


/*ArrayList Quarter1=new ArrayList();
ArrayList Quarter2=new ArrayList();
ArrayList Quarter3=new ArrayList();
ArrayList Quarter4=new ArrayList();*/

String roId="",roCode="",ro="";


//try{

//Class.forName(driver_class).newInstance();
roCode= (request.getParameter("userid") != null) ? request.getParameter("userid") : "";
String financialyear = (request.getParameter("financialyear")==null)? new String():request.getParameter("financialyear");
// roId = "1113";//(request.getParameter("roid") != null) ? request.getParameter("roid") : "";
// strPrd=request.getParameter("product");
//strPrd=(request.getParameter("product") != null) ? request.getParameter("product") : "1001083";

//prevQuery=request.getQueryString();
//out.println("Product Id::"+strPrd+"::"+roId+"::"+roCode);
//session.setAttribute("roid",roCode);
//session.setAttribute("Product",strPrd);

conn = getCon();
java.sql.Statement stRoid=conn.createStatement();
String strRO="select roid from romaster where rocode=upper('"+roCode+"')";

java.sql.ResultSet rsRoid=stRoid.executeQuery(strRO);
System.out.println();
if(rsRoid.next())
{
roId=rsRoid.getString(1);
}
else
{
roId="0";
}

//out.println(ro);




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


pst1.setString(4,aprMS);
pst1.setString(5,aprHSD);
pst1.setString(6,aprAlpg);
pst1.setString(7,aprLubes);
pst1.setString(8,aprTyres);
pst1.setString(9,aprRcare_Tyres);
pst1.setString(10,aprRcare_Lubes);
pst1.setString(11,aprRcare_spares);
pst1.setString(12,aprRcare_service);
pst1.setString(13,aprMS);




pst1.setString(14,mayMS);
pst1.setString(15,mayHSD);
pst1.setString(16,mayAlpg);
pst1.setString(17,mayLubes);
pst1.setString(18,mayTyres);
pst1.setString(19,mayRcare_Tyres);
pst1.setString(20,mayRcare_Lubes);
pst1.setString(21,mayRcare_spares);
pst1.setString(22,mayRcare_service);
pst1.setString(23,mayAFS);




pst1.setString(24,junMS);
pst1.setString(25,junHSD);
pst1.setString(26,junAlpg);
pst1.setString(27,junLubes);
pst1.setString(28,junTyres);
pst1.setString(29,junRcare_Tyres);
pst1.setString(30,junRcare_Lubes);
pst1.setString(31,junRcare_spares);
pst1.setString(32,junRcare_service);
pst1.setString(33,junAFS);
}
updateQuery =pst1.executeUpdate();

//pst1.addBatch();
//pst1.executeUpdate();
//strUpdateFlag = "true";

//out.println("test 1");


}
catch(Exception e)
{

out.println("Error while inserting readings1"+e);
// e.printStackTrace();
//strUpdateFlag = "false";
//conn.commit();

//return;
}

pst1.close();



try
{
//conn.setAutoCommit(false);
conn=getCon();

String insrtStmt2="insert into CROSSLNK.QUARTER2TARGETDATA(julMS,julHSD,julAlpg,julLubes,julTyres,julRcare_Tyres,julRcare_Lubes,julRcare_Spares,julRcare_Service,julAFS,augMS,augHSD,augAlpg,augLubes,augTyres,augRcare_Tyres,augRcare_Lubes,augRcare_spares,augRcare_service,augAFS,sepMS,sepHSD,sepAlpg,sepLubes,sepTyres,sepRcare_Tyres,sepRcare_Lubes,sepRcare_spares,sepRcare_service,sepAFS) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pst2 =conn.prepareStatement(insrtStmt2);

int updateQuery;

{
String julMS = (request.getParameter("julMS")==null)? new String ():request.getParameter("julMS");
String julHSD = (request.getParameter("julHSD")==null)? new String ():request.getParameter("julHSD");
String julAlpg = (request.getParameter("julAlpg")==null)? new String ():request.getParameter("julAlpg");
String julLubes = (request.getParameter("julLubes")==null)? new String ():request.getParameter("julLubes");
String julTyres = (request.getParameter("julTyres")==null)? new String ():request.getParameter("julTyres");
String julRcare_Tyres = (request.getParameter("julRcare_Tyres")==null)? new String ():request.getParameter("julRcare_Tyres");
String julRcare_Lubes = (request.getParameter("julRcare_Lubes")==null)? new String ():request.getParameter("julRcare_Lubes");
String julRcare_spares = (request.getParameter("julRcare_spares")==null)? new String ():request.getParameter("julRcare_spares");
String julRcare_service = (request.getParameter("julRcare_service")==null)? new String ():request.getParameter("julRcare_service");
String julAFS = (request.getParameter("julAFS")==null)? new String ():request.getParameter("julAFS");


String augMS = (request.getParameter("augMS")==null)? new String ():request.getParameter("augMS");
String augHSD = (request.getParameter("augHSD")==null)? new String ():request.getParameter("augHSD");
String augAlpg = (request.getParameter("augAlpg")==null)? new String ():request.getParameter("augAlpg");
String augLubes = (request.getParameter("augLubes")==null)? new String ():request.getParameter("augLubes");
String augTyres = (request.getParameter("augTyres")==null)? new String ():request.getParameter("augTyres");
String augRcare_Tyres = (request.getParameter("augRcare_Tyres")==null)? new String ():request.getParameter("augRcare_Tyres");
String augRcare_Lubes = (request.getParameter("augRcare_Lubes")==null)? new String ():request.getParameter("augRcare_Lubes");
String augRcare_spares = (request.getParameter("augRcare_spares")==null)? new String ():request.getParameter("augRcare_spares");
String augRcare_service = (request.getParameter("augRcare_service")==null)? new String ():request.getParameter("augRcare_service");
String augAFS = (request.getParameter("augAFS")==null)? new String ():request.getParameter("augAFS");

String sepMS = (request.getParameter("sepMS")==null)? new String ():request.getParameter("sepMS");
String sepHSD = (request.getParameter("sepHSD")==null)? new String ():request.getParameter("sepHSD");
String sepAlpg = (request.getParameter("sepAlpg")==null)? new String ():request.getParameter("sepAlpg");
String sepLubes = (request.getParameter("sepLubes")==null)? new String ():request.getParameter("sepLubes");
String sepTyres = (request.getParameter("sepTyres")==null)? new String ():request.getParameter("sepTyres");
String sepRcare_Tyres = (request.getParameter("sepRcare_Tyres")==null)? new String ():request.getParameter("sepRcare_Tyres");
String sepRcare_Lubes = (request.getParameter("sepRcare_Lubes")==null)? new String ():request.getParameter("sepRcare_Lubes");
String sepRcare_spares = (request.getParameter("sepRcare_spares")==null)? new String ():request.getParameter("sepRcare_spares");
String sepRcare_service = (request.getParameter("sepRcare_service")==null)? new String ():request.getParameter("sepRcare_service");
String sepAFS = (request.getParameter("sepAFS")==null)? new String ():request.getParameter("sepAFS");

pst2.setString(4,julMS);
pst2.setString(5,julHSD);
pst2.setString(6,julAlpg);
pst2.setString(7,julLubes);
pst2.setString(8,julTyres);
pst2.setString(9,julRcare_Tyres);
pst2.setString(10,julRcare_Lubes);
pst2.setString(11,julRcare_spares);
pst2.setString(12,julRcare_service);
pst2.setString(13,julAFS);



pst2.setString(14,augMS);
pst2.setString(15,augHSD);
pst2.setString(16,augAlpg);
pst2.setString(17,augLubes);
pst2.setString(18,augTyres);
pst2.setString(19,augRcare_Tyres);
pst2.setString(20,augRcare_Lubes);
pst2.setString(21,augRcare_spares);
pst2.setString(22,augRcare_service);
pst2.setString(23,augAFS);



pst2.setString(24,sepMS);
pst2.setString(25,sepHSD);
pst2.setString(26,sepAlpg);
pst2.setString(27,sepLubes);
pst2.setString(28,sepTyres);
pst2.setString(29,sepRcare_Tyres);
pst2.setString(30,sepRcare_Lubes);
pst2.setString(31,sepRcare_spares);
pst2.setString(32,sepRcare_service);
pst2.setString(33,sepAFS);

}
updateQuery=pst2.executeUpdate();
//pst2.addBatch();



//pst2.executeBatch();
//strUpdateFlag = "true";

//out.println("test 1")



}
catch(Exception e)
{

out.println("Error while inserting reading2"+e);
//strUpdateFlag = "false";
//conn.commit();

//return;
}

pst2.close();




try
{
//conn.setAutoCommit(false);
conn=getCon();

String insrtStmt3="insert into CROSSLNK.QUARTER3TARGETDATA(octMS,octHSD,octAlpg,octLubes,octTyres,octRcare_Tyres,octRcare_Lubes,octRcare_Spares,octRcare_Service,octAFS,novMS,novHSD,novAlpg,novLubes,novTyres,novRcare_Tyres,novRcare_Lubes,novRcare_spares,novRcare_service,novAFS,decMS,decHSD,decAlpg,decLubes,decTyres,decRcare_Tyres,decRcare_Lubes,decRcare_spares,decRcare_service,decAFS) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pst3 =conn.prepareStatement(insrtStmt3);

int updateQuery;

{
String octMS = (request.getParameter("octMS")==null)? new String ():request.getParameter("octMS");
String octHSD = (request.getParameter("octHSD")==null)? new String ():request.getParameter("octHSD");
String octAlpg = (request.getParameter("octAlpg")==null)? new String ():request.getParameter("octAlpg");
String octLubes = (request.getParameter("octLubes")==null)? new String ():request.getParameter("octLubes");
String octTyres = (request.getParameter("octTyres")==null)? new String ():request.getParameter("octTyres");
String octRcare_Tyres = (request.getParameter("octRcare_Tyres")==null)? new String ():request.getParameter("octRcare_Tyres");
String octRcare_Lubes = (request.getParameter("octRcare_Lubes")==null)? new String ():request.getParameter("octRcare_Lubes");
String octRcare_spares = (request.getParameter("octRcare_spares")==null)? new String ():request.getParameter("octRcare_spares");
String octRcare_service = (request.getParameter("octRcare_service")==null)? new String ():request.getParameter("octRcare_service");
String octAFS = (request.getParameter("octAFS")==null)? new String ():request.getParameter("octAFS");


String novMS = (request.getParameter("novMS")==null)? new String ():request.getParameter("novMS");
String novHSD = (request.getParameter("novHSD")==null)? new String ():request.getParameter("novHSD");
String novAlpg = (request.getParameter("novAlpg")==null)? new String ():request.getParameter("novAlpg");
String novLubes = (request.getParameter("novLubes")==null)? new String ():request.getParameter("novLubes");
String novTyres = (request.getParameter("novTyres")==null)? new String():request.getParameter("novTyres");
String novRcare_Tyres = (request.getParameter("novRcare_Tyres")==null)? new String ():request.getParameter("novRcare_Tyres");
String novRcare_Lubes = (request.getParameter("novRcare_Lubes")==null)? new String ():request.getParameter("novRcare_Lubes");
String novRcare_spares = (request.getParameter("novRcare_spares")==null)? new String ():request.getParameter("novRcare_spares");
String novRcare_service = (request.getParameter("novRcare_service")==null)? new String ():request.getParameter("novRcare_service");
String novAFS = (request.getParameter("novAFS")==null)? new String ():request.getParameter("novAFS");


String decMS = (request.getParameter("decMS")==null)? new String ():request.getParameter("decMS");
String decHSD = (request.getParameter("decHSD")==null)? new String ():request.getParameter("decHSD");
String decAlpg = (request.getParameter("decAlpg")==null)? new String ():request.getParameter("decAlpg");
String decLubes = (request.getParameter("decLubes")==null)? new String ():request.getParameter("decLubes");
String decTyres = (request.getParameter("decTyres")==null)? new String ():request.getParameter("decTyres");
String decRcare_Tyres = (request.getParameter("decRcare_Tyres")==null)? new String ():request.getParameter("decRcare_Tyres");
String decRcare_Lubes = (request.getParameter("decRcare_Lubes")==null)? new String ():request.getParameter("decRcare_Lubes");
String decRcare_spares = (request.getParameter("decRcare_spares")==null)? new String ():request.getParameter("decRcare_spares");
String decRcare_service = (request.getParameter("decRcare_service")==null)? new String ():request.getParameter("decRcare_service");
String decAFS = (request.getParameter("decAFS")==null)? new String ():request.getParameter("decAFS");


pst3.setString(4,octMS);
pst3.setString(5,octHSD);
pst3.setString(6,octAlpg);
pst3.setString(7,octLubes);
pst3.setString(8,octTyres);
pst3.setString(9,octRcare_Tyres);
pst3.setString(10,octRcare_Lubes);
pst3.setString(11,octRcare_spares);
pst3.setString(12,octRcare_service);
pst3.setString(13,octAFS);




pst3.setString(14,novMS);
pst3.setString(15,novHSD);
pst3.setString(16,novAlpg);
pst3.setString(17,novLubes);
pst3.setString(18,novTyres);
pst3.setString(19,novRcare_Tyres);
pst3.setString(20,novRcare_Lubes);
pst3.setString(21,novRcare_spares);
pst3.setString(22,novRcare_service);
pst3.setString(23,novAFS);




pst3.setString(24,decMS);
pst3.setString(25,decHSD);
pst3.setString(26,decAlpg);
pst3.setString(27,decLubes);
pst3.setString(28,decTyres);
pst3.setString(29,decRcare_Tyres);
pst3.setString(30,decRcare_Lubes);
pst3.setString(31,decRcare_spares);
pst3.setString(32,decRcare_service);
pst3.setString(33,decAFS);
}
updateQuery=pst3.executeUpdate();
//pst3.addBatch();


//pst3.executeBatch();
//strUpdateFlag = "true";

//out.println("test 1");


}
catch(Exception e)
{

out.println("Error while inserting reading3"+e);
//strUpdateFlag = "false";
//conn.commit();
return;
}

pst3.close();



try
{
// conn.setAutoCommit(false);
conn=getCon();

String insrtStmt4="insert into CROSSLNK.QUARTER4TARGETDATA(janMS,janHSD,janAlpg,janLubes,janTyres,janRcare_Tyres,janRcare_Lubes,janRcare_Spares,janRcare_Service,janAFS,febMS,febHSD,febAlpg,febLubes,febTyres,febRcare_Tyres,febRcare_Lubes,febRcare_spares,febRcare_service,febAFS,marMS,marHSD,marAlpg,marLubes,marTyres,marRcare_Tyres,marRcare_Lubes,marRcare_spares,marRcare_service,marAFS) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pst4 =conn.prepareStatement(insrtStmt4);

int updateQuery;

{
String janMS = (request.getParameter("janMS")==null)? new String ():request.getParameter("janMS");
String janHSD = (request.getParameter("janHSD")==null)? new String ():request.getParameter("janHSD");
String janAlpg = (request.getParameter("janAlpg")==null)? new String ():request.getParameter("janAlpg");
String janLubes = (request.getParameter("janLubes")==null)? new String ():request.getParameter("janLubes");
String janTyres = (request.getParameter("janTyres")==null)? new String ():request.getParameter("janTyres");
String janRcare_Tyres = (request.getParameter("janRcare_Tyres")==null)? new String ():request.getParameter("janRcare_Tyres");
String janRcare_Lubes = (request.getParameter("janRcare_Lubes")==null)? new String ():request.getParameter("janRcare_Lubes");
String janRcare_spares = (request.getParameter("janRcare_Spares")==null)? new String ():request.getParameter("janRcare_spares");
String janRcare_service = (request.getParameter("janRcare_Service")==null)? new String ():request.getParameter("janRcare_service");
String janAFS = (request.getParameter("janAFS")==null)? new String ():request.getParameter("janAFS");


String febMS = (request.getParameter("febMS")==null)? new String ():request.getParameter("febMS");
String febHSD = (request.getParameter("febHSD")==null)? new String ():request.getParameter("febHSD");
String febAlpg = (request.getParameter("febAlpg")==null)? new String ():request.getParameter("febAlpg");
String febLubes = (request.getParameter("febLubes")==null)? new String ():request.getParameter("febLubes");
String febTyres = (request.getParameter("febTyres")==null)? new String ():request.getParameter("febTyres");
String febRcare_Tyres = (request.getParameter("febRcare_Tyres")==null)? new String ():request.getParameter("febRcare_Tyres");
String febRcare_Lubes = (request.getParameter("febRcare_Lubes")==null)? new String ():request.getParameter("febRcare_Lubes");
String febRcare_spares = (request.getParameter("febRcare_spares")==null)? new String ():request.getParameter("febRcare_spares");
String febRcare_service = (request.getParameter("febRcare_service")==null)? new String ():request.getParameter("febRcare_service");
String febAFS = (request.getParameter("febAFS")==null)? new String ():request.getParameter("febAFS");

String marMS = (request.getParameter("marMS")==null)? new String ():request.getParameter("marMS");
String marHSD = (request.getParameter("marHSD")==null)? new String ():request.getParameter("marHSD");
String marAlpg = (request.getParameter("marAlpg")==null)? new String ():request.getParameter("marAlpg");
String marLubes = (request.getParameter("marLubes")==null)? new String ():request.getParameter("marLubes");
String marTyres = (request.getParameter("marTyres")==null)? new String ():request.getParameter("marTyres");
String marRcare_Tyres = (request.getParameter("marRcare_Tyres")==null)? new String ():request.getParameter("marRcare_Tyres");
String marRcare_Lubes = (request.getParameter("marRcare_Lubes")==null)? new String ():request.getParameter("marRcare_Lubes");
String marRcare_spares = (request.getParameter("marRcare_spares")==null)? new String ():request.getParameter("marRcare_spares");
String marRcare_service = (request.getParameter("marRcare_service")==null)? new String ():request.getParameter("marRcare_service");
String marAFS = (request.getParameter("marAFS")==null)? new String ():request.getParameter("marAFS");


pst4.setString(1,janMS);
pst4.setString(2,janHSD);
pst4.setString(3,janAlpg);
pst4.setString(4,janTyres);
pst4.setString(5,janTyres);
pst4.setString(6,janRcare_Tyres);
pst4.setString(7,janRcare_Lubes);
pst4.setString(8,janRcare_spares);
pst4.setString(9,janRcare_service);
pst4.setString(10,janAFS);




pst4.setString(11,febMS);
pst4.setString(12,febHSD);
pst4.setString(13,febAlpg);
pst4.setString(14,febLubes);
pst4.setString(15,febTyres);
pst4.setString(16,febRcare_Tyres);
pst4.setString(17,febRcare_Lubes);
pst4.setString(18,febRcare_spares);
pst4.setString(19,febRcare_service);
pst4.setString(20,febAFS);




pst4.setString(21,marMS);
pst4.setString(22,marHSD);
pst4.setString(23,marAlpg);
pst4.setString(24,marLubes);
pst4.setString(25,marTyres);
pst4.setString(26,marRcare_Tyres);
pst4.setString(27,marRcare_Lubes);
pst4.setString(28,marRcare_spares);
pst4.setString(29,marRcare_service);
pst4.setString(30,marAFS);
}
updateQuery=pst4.executeUpdate();

//pst4.addBatch();

//pst4.executeBatch();
// strUpdateFlag = "true";
//out.println("test 1");


}
catch(Exception e)
{

e.printStackTrace();
//strUpdateFlag = "false";

//conn.commit();
return;
}

pst4.close();




<script>
function validate()
{
alert(error);
return;
}
</script>

</body>

<%



}
catch(Exception ce)
{
ce.printStackTrace();

}
finally
{
try
{


if(pst1!= null) pst1.close();
if(pst2!= null) pst2.close();
if(pst3!= null) pst3.close();
if(pst4!= null) pst4.close();

conn.close();

//out.println("con.close()");
}
catch(Exception e)
{
e.printStackTrace();
}
}

%>


</html>

Please suggest any corrections
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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
It would be greatful if you could help me on where i am going wrong
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1726
    
  14

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
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
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.
 
GeeCON Prague 2014
 
subject: Error while inserting readings1java.sql.SQLException: Missing IN or OUT parameter at index:: 1