unable to execute prepared statement
my code
Code :
package jdbcstatements;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Insertion {
public static void main(String[] args) throws SQLException {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
Connection con=DriverManager.getConnection( url, "scott", "tiger");
System.out.println("connection created");
try{
String sql = "INSERT EMP VALUES(?)";
PreparedStatement prest = con.prepareStatement(sql);
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter employee name:");
String ename = bf.readLine();
prest.setString(2,ename);
System.out.println("Enter salaryof employee:");
int sal = Integer.parseInt(bf.readLine());
prest.setInt(2, sal);
int count = prest.executeUpdate();
System.out.println(count + "row(s) affected");
con.close();
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
error
connection created
Enter movie name:
xxxx
SQL statement is not executed!
Re: unable to execute prepared statement
Why swallow all the exception information....
Code :
catch (SQLException s){
s.printStrackTrace();//print the stack trace - this is important information
System.out.println("SQL statement is not executed!");
}
What does the exception say?
And finally, please use the code tags. It makes your code that much more readable.