java.sql.SQLException:No value specified for parameter 2 whats the reason?
807605Jun 14 2007 — edited Jun 14 2007public class DataBaseImpl
{
Connection con=null;
PreparedStatement ps=null;
Statement stmt=null;
public void createTable()
{
try
{
class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection("jdbc:mysql://localhost/threadpool?user=root&password=");
stmt=con.createStatement();
String str="create table thread"+"(unique_Id varchar(100) primary key,"+"parent_id int,"+"data varchar(100))";
stmt.execute(str);
String str1="create table thread1"+"(unique_Id varchar(100) ,"+"child_id int)";
stmt.execute(str1);
}
catch(Exception e)
{
System.out.println(e);
}
}
public void insertThread(String unique,int id,String data)
{
try
{
ps=con.prepareStatement("insert into thread values(?,?,?)");
ps.setString(1,unique);
ps.setInt(2,id);
ps.setString(3,data);
ps.executeUpdate();
}
catch(Exception e)
{
System.out.println(e);
}
}
public void insertThread1(String unique,int cid)
{
try
{
ps=con.prepareStatement("insert into thread1 values(?,?)");
ps.setString(1,unique);
ps.setInt(2,cid);
ps.executeUpdate();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
in that program,Iam called the createThread method only one time,then iam periodically called the insertThread and insertThread1 method.Initially there is no exception thrown,after a few while the exception arises in both the method.The exception is java.sql.SQLException:No value specified for parameter 2.... I dont knw why that exception arises...? Anyone tell me the solution for this problem...........................