Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.sql.SQLException:No value specified for parameter 2 whats the reason?

807605Jun 14 2007 — edited Jun 14 2007
public 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...........................
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2007
Added on Jun 14 2007
4 comments
5,660 views