Create a Package in Oracle
for Test in Java
I create a package in oracle that need to be tested
in java. What am I supppose to do?
By Suman
It's not a tough thing.
Say for example you have a package pkg_manage_emp_info,
and inside it there a proc/function sp_select_emp_leave(in,in,out,in out)
that you need to be called from java class....
Need to import the following classes/interfaces:------>>>>
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import oracle.jdbc.internal.OracleTypes;
and ojdbc14.jar need to be in your project classpath.
CallableStatement cstmt =
null;
String queryString =
"{CALL pkg_manage_emp_info.sp_select_emp_leave(?,?,?,?)}";
Connection conn =
null;
try
{
Class.forName(
"oracle.jdbc.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:DB_NAME", "user_name",
"password");
cstmt = conn.prepareCall(procedureString);
cstmt.setString(1,
""//set the value of in parameter);
cstmt.setString(2,
""//set the value of 2nd in parameter);
//for out or in/out param---
cstmt.registerOutParameter(3, Types.VARCHAR,
//if it is a ref_cursor type out var then use --OracleTypes.CURSOR);
cstmt.registerOutParameter(4, Types.INT);
cstmt.executeQuery();
String empBalLeave = (String) cstmt.getObject(3);
//if it is a ref cursor then
//ResulSet rs = (ResultSet)cstmt.getObject(3);
while(rs.next){
---
}
}
catch
(Exception ex)
{
ex.printStackTrace();
}
Have a Oracle Question
Do
you have an Oracle Question?
Oracle Books
Oracle Certification,
Database Administration, SQL, Application, Programming Reference Books
Oracle Application
Oracle
Application Hints and Tips
Oracle Home
Oracle
Database, SQL, Application, Programming Tips
All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
All product names are trademarks of their respective
companies.
The site www.erpgreat.com is not affiliated with or endorsed
by any company listed at this site.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
The content on this site may not be reproduced
or redistributed without the express written permission of
www.erpgreat.com or the content authors.
|