sqlException.....

Is there any wrong in my code?sqlException:parameter 2 is missing.... arises in the insertThread method...?Anyone knw the reason for that exception...?

publicclass DataBaseImpl

{

Connection con=null;

PreparedStatement ps=null;

Statement stmt=null;

publicvoid 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);

}

}

publicvoid 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);

}

}

publicvoid 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);

}

}

}publicclass DataBaseImpl

{

Connection con=null;

PreparedStatement ps=null;

Statement stmt=null;

publicvoid 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);

}

}

publicvoid 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);

}

}

publicvoid 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);

}

}

}

[5777 byte] By [83Krisha] at [2007-11-27 7:53:02]
# 1
first i dunno from where you called insert thread..secondly..you have posted ur whole code twicei don't think anything is wrong with ur preparedstatement...ul have to be more clear.
KayDeEa at 2007-7-12 19:34:17 > top of Java-index,Java Essentials,Java Programming...
# 2
I don't think anything wrong in your code, I use the exact copy of your code and it working fine, I use mysql-connector-java-3.1.12-bin driver.With minor changes, class.forName as Class.forName and the java file you paste twice.
jackwenttohilla at 2007-7-12 19:34:17 > top of Java-index,Java Essentials,Java Programming...
# 3

hi friend,initially iam called the createtable method only one time,then iam periodically calling insertThread and insertthread1 method.Initially there is no exception arises but after a few while java.sql.sqlException arises:parameter 2 missing in insertThread method..... but the table is updated.... i dont know why this exception arises...?do u knw the reason....

83Krisha at 2007-7-12 19:34:17 > top of Java-index,Java Essentials,Java Programming...
# 4
can you send us the code how you are calling. complete flows.
jackwenttohilla at 2007-7-12 19:34:17 > top of Java-index,Java Essentials,Java Programming...