Home » SQL & PL/SQL » SQL & PL/SQL » Insert data through Java class (Oracle 10g)
Insert data through Java class [message #632843] Fri, 06 February 2015 03:56 Go to next message
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 #632853 is a reply to message #632843] Fri, 06 February 2015 04:49 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
did you commit the delete?
Re: Insert data through Java class [message #632857 is a reply to message #632853] Fri, 06 February 2015 05:36 Go to previous messageGo to next message
Xandot
Messages: 235
Registered: January 2014
Location: India
Senior Member
Yup.
Re: Insert data through Java class [message #632859 is a reply to message #632857] Fri, 06 February 2015 05:42 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
How did you commit it?
Re: Insert data through Java class [message #632860 is a reply to message #632857] Fri, 06 February 2015 05:42 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Does the procedure hang the 2nd time you run it or does it return without error?
Re: Insert data through Java class [message #632863 is a reply to message #632860] Fri, 06 February 2015 05:58 Go to previous messageGo to next message
Xandot
Messages: 235
Registered: January 2014
Location: India
Senior Member
Nope its not return any error message, its executed properly and I use "commit" for inserting the data.

Is there session related issue?

[Updated on: Fri, 06 February 2015 05:59]

Report message to a moderator

Re: Insert data through Java class [message #632869 is a reply to message #632863] Fri, 06 February 2015 06:47 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
As Lalit asks - how did you commit it?
You're starting a new session (why?), a commit outside of that new session will have no impact on it.
Re: Insert data through Java class [message #632871 is a reply to message #632869] Fri, 06 February 2015 07:24 Go to previous message
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.
Previous Topic: extract character between points
Next Topic: Getting boundaries
Goto Forum:
  


Current Time: Fri Apr 26 07:50:26 CDT 2024