I am trying to insert/update/delete a row using jdbc. Inserting is working, and I only changed the query string (or insertTableSQL) By debugging, I suspect that executeUpdate() is not terminated and console does not show me any error message. (JUST BLANK)
[EDIT]
The program is stuck while executeUpate() is exeucting, meaning that I cannot even see the return value
Instead of using query string, I also tried PreparedStatement but no luck :(
String deleteRecordSQL = "DELETE mytable WHERE id = ?";
PreparedStatement ps = dbConnection.prepareStatement(deleteRecordSQL);
ps.setInt(1, 6);
ps.executeUpdate();
Full Code:
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class DeleteRow {
private static final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String DB_CONNECTION = "";
private static final String DB_USER = "";
private static final String DB_PASSWORD = "";
public static void main(String[] argv) {
try {
deleteRecordFromDbUserTable();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
private static void deleteRecordFromDbUserTable() throws SQLException {
Connection dbConnection = null;
Statement statement = null;
try {
dbConnection = getDBConnection();
statement = dbConnection.createStatement();
statement.executeUpdate("DELETE mytable WHERE id = 6");
System.out.println("Record is deleted!");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (statement != null) {
statement.close();
}
if (dbConnection != null) {
dbConnection.close();
}
}
}
private static Connection getDBConnection() {
Connection dbConnection = null;
try {
Class.forName(DB_DRIVER);
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try {
dbConnection = DriverManager.getConnection(
DB_CONNECTION, DB_USER,DB_PASSWORD);
return dbConnection;
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return dbConnection;
}
}
Any help?
THIS IS NOT THE OFFICIAL ANSWER, BUT THE PROBLEM IS RESOLVED SOMEHOW
There was Java update notification, and I followed it. After update, the status of JRE System Library(JavaSE - 1.7) is changed to unbound. I changed Execution environment to JavaSE - 1.6 (Oracle WebLogic Server 11gR1 (10.3.6) JRE), and the issue was resolved..weird..
There was no syntax problem
If anyone can explain me how this issue could be resolved, your help would be much appreciated.
FYI.