Insert data through Java class [message #632843] |
Fri, 06 February 2015 03:56 |
Xandot
Messages: 235 Registered: January 2014 Location: India
|
Senior Member |
|
|
Hi All,
I am facing one issue when I'm trying to execute java class through pl/sql procedure as follows :-
I have one java class which is insert records in EMP table.
public class EmpTest {
public void insertEmp() throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@xxxx.xxx.xx.com:1521:abc", "user", "password");
String sqlQuery = "insert into emp_table "
+ "(empid, empname)VALUES (?,?)";
PreparedStatement pstmt = conn.prepareStatement(sqlQuery);
pstmt.setString(1, "emp01");
pstmt.setString(2, "emp name");
pstmt.execute();
}
}
I have created one procedure to call java class:
CREATE OR REPLACE PROCEDURE Insert_Records as
LANGUAGE JAVA NAME 'EmpTest.insertEmp()' ;
When I execute above procedure first time It'll show me records in EMP table then I delete the inserted records and again I execute this procedure on second time It'll not inserted the records.
What is the main cause that data is not inserted on second time. It'll insert records again when I reconnect my DB.
Thanks
Xandot
|
|
|
|
|
|
|
|
|
Re: Insert data through Java class [message #632871 is a reply to message #632869] |
Fri, 06 February 2015 07:24 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
In my opinion, the records are never committed for the session inserting the records, you do a commit on other session which has nothing to commit. You also issue a delete which deletes nothing. You insert again, and repeat the same steps, and you see nothing.
|
|
|