gudii9
asked on
java stored proc example
Hi,
I am working on below
http://www.gokhanatil.com/2009/07/how-to-develop-java-stored-procedures.html
storedproc code is as below
please advise
proc.png
I am working on below
http://www.gokhanatil.com/2009/07/how-to-develop-java-stored-procedures.html
import java.sql.*;
import oracle.jdbc.*;
public class JavaSample {
public static void main(String[] args) throws ClassNotFoundException {
JavaSample js=new JavaSample();
js.insert_into_table(100, "gp", "gp@gp.com");
}
public static void insert_into_table(int ID, String Name, String Email) throws ClassNotFoundException {
try {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:XE";
String username = "sample";
String password = "admin";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
// return conn;
//Connection DB = DriverManager.getConnection("jdbc:default:connection:");
String SQL ="INSERT INTO sampletable VALUES (?,?,?)";
PreparedStatement cmd = conn.prepareStatement(SQL);
cmd.setInt(1, ID);
cmd.setString(2, Name );
cmd.setString(3, Email );
cmd.executeUpdate();
cmd.close();
}
catch(SQLException e) {
System.err.println( "Error: " + e.getMessage());
}
}
}
storedproc code is as below
CREATE PROCEDURE TestForJava
( id NUMBER, name VARCHAR2, email VARCHAR2 )
AS LANGUAGE JAVA
NAME 'JavaSample.insert_into_table( int,
java.lang.String, java.lang.String )';
/
how to improve my code. I wonder why two times ClassNotFoundExceptionplease advise
proc.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The stored procedure and your code are entirely unrelated
Do we need throws twice
what do you mean?
ASKER
from both methods i mean as below bolded
public static void main(String[] args) throws ClassNotFoundException {
public static void insert_into_table(int ID, String Name, String Email) throws ClassNotFoundException {
public static void main(String[] args) throws ClassNotFoundException {
public static void insert_into_table(int ID, String Name, String Email) throws ClassNotFoundException {
Of course if one calls the other.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't see why my post is the accepted solution?
Did I provide a solution?
Did I provide a solution?
The only really significant comment to this question is https://www.experts-exchange.com/questions/28993984/java-stored-proc-example.html?anchorAnswerId=41953498#a41953498 actually ;)
ASKER