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

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...........................

[1821 byte] By [83Krisha] at [2007-11-27 7:37:27]
# 1
Maybe parameter 2 is null and isn't allowed to be?Read this please: http://forum.java.sun.com/help.jspa?sec=formattingAnd then tell us which of these actions actually raises this exception.
CeciNEstPasUnProgrammeura at 2007-7-12 19:18:02 > top of Java-index,Java Essentials,Java Programming...
# 2
but iamnot passing null value.... but it shows the same exception... how to avoid this exception... can u tell me the way,,,?
83Krisha at 2007-7-12 19:18:02 > top of Java-index,Java Essentials,Java Programming...
# 3

I am surprised this code works at all. You have two insert statements both with the poor practice of not listing columns and they don't have the same column count. So I guess one of those columns is not allowed to be null.

Personally I'd consider flushing this code down the toilet and starting over. The way you close your PreparedStatement and other objects for example? Not good.

cotton.ma at 2007-7-12 19:18:02 > top of Java-index,Java Essentials,Java Programming...
# 4
Oh wait those are different tables.Well whatever. The other comments still apply and you are passing null despite your claims to the contrary.
cotton.ma at 2007-7-12 19:18:03 > top of Java-index,Java Essentials,Java Programming...