
Identify the reason for SQLException exception, which is encountered when the developer tries to run the following code snippet to insert a row in the Status table:
String str = "INSERT INTO Status VALUES (?,?)"; PreparedStatement ps = con.prepareStatement(str); ResultSet rs=ps.createResultset(); ps.setString(1,"bk67"); ps.setString(2,"m40"); rs=ps.executeUpdate();

Try this:
import java.sql.*;
class InsertData{
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
String str = "INSERT INTO Status(name,value) VALUES (?,?)";
PreparedStatement ps = con.prepareStatement(str);
ps.setString(1,"bk67");
ps.setString(2,"m40");
ps.executeUpdate();
}
catch(Exception e){
System.out.println(e);
}
}
}
For the above code, we have created the following table:
CREATE TABLE `status` (
`id` bigint(255) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`value` varchar(255) default NULL,
PRIMARY KEY (`id`)
);
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.