bboss 지구층 프레임워크Callable DBUtil 구성 요소 실행 저장 프로세스 및 함수 실례
20154 단어 저장 프로세스함수.bboss지구층callabledbutil
함수 실행 인스턴스:
package com.frameworkset.common;
import javax.transaction.RollbackException;
import com.frameworkset.common.poolman.CallableDBUtil;
import com.frameworkset.common.poolman.Record;
import com.frameworkset.orm.transaction.TransactionManager;
public class TestCallableFunction {
public static void testTest_fWithPositionIndex()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{? = call Test_f(?,?,?)}");
callableDBUtil.registerOutParameter(1, java.sql.Types.INTEGER);
callableDBUtil.setInt(2, 10);
callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(4, java.sql.Types.VARCHAR);
callableDBUtil.executeCallable();
System.out.println("ret:" + callableDBUtil.getInt(1));
System.out.println("name:" + callableDBUtil.getString(3));
System.out.println("name1:" + callableDBUtil.getString(4));
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
*
*/
public static void testTest_fWithNameIndex()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{? = call Test_f(?,?,?)}");
callableDBUtil.registerOutParameter(1, java.sql.Types.INTEGER);
callableDBUtil.setInt(2, 10);
callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(4, java.sql.Types.VARCHAR);
callableDBUtil.executeCallable();
System.out.println("ret:" + callableDBUtil.getInt(1));
System.out.println("name:" + callableDBUtil.getString(3));
System.out.println("name1:" + callableDBUtil.getString(4));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void testTest_fWithNameIndexForXMLString()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{? = call Test_f(?,?,?)}");
callableDBUtil.registerOutParameter(1, java.sql.Types.INTEGER);
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt(2, 10);
callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(4, java.sql.Types.VARCHAR);
String xmlString = callableDBUtil.executeCallableForXML();
// System.out.println("name1:" + callableDBUtil.getString("name"));
// System.out.println("name2:" + callableDBUtil.getString("name1"));
System.out.println("xmlString:" + xmlString);
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
*
*/
public static void testTest_fWithNameIndexForXMLStringRowHandler()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{? = call Test_f(?,?,?)}");
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.registerOutParameter(1, java.sql.Types.INTEGER);
callableDBUtil.setInt(2, 10);
callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(4, java.sql.Types.VARCHAR);
String xmlString = callableDBUtil.executeCallableForXML(new com.frameworkset.common.poolman.handle.RowHandler()
{
/**
*
* @param rowValue
*/
public void handleRow(Object rowValue,Record record)
{
StringBuffer objects = (StringBuffer)rowValue;
objects.append(record);
System.out.println("objects:" + objects);
}
});
// System.out.println("name1:" + callableDBUtil.getString("name"));
// System.out.println("name2:" + callableDBUtil.getString("name1"));
System.out.println("xmlString:" + xmlString);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void testTest_fWithNameIndexForObject()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{? = call Test_f(?,?,?)}");
callableDBUtil.registerOutParameter(1, java.sql.Types.INTEGER);
callableDBUtil.setInt(2, 10);
callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(4, java.sql.Types.VARCHAR);
Test_f tets = (Test_f)callableDBUtil.executeCallableForObject(Test_f.class,new com.frameworkset.common.poolman.handle.RowHandler()
{
public void handleRow(Object rowValue,Record record) {
Test_f objects = (Test_f)rowValue;
try
{
objects.setRet(record.getString(1));
objects.setName(record.getString(3));
objects.setName1(record.getString(4));
}
catch(Exception e)
{
}
// origine.put(new Integer(4), "55");
System.out.println("rowValue:" + rowValue);
}
}
);
// System.out.println("name1:" + callableDBUtil.getString("name"));
// System.out.println("name2:" + callableDBUtil.getString("name1"));
System.out.println("Test_f is " + tets);
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
* / / 、 , poolman
* ; / / ,
* 。
* @param i 0 ,1
*/
public static void testTest_fWithNameIndexForObjectTx(int i)
{
TransactionManager tm = new TransactionManager();
try
{
tm.begin();
CallableDBUtil callableDBUtil = new CallableDBUtil();
callableDBUtil.prepareCallable("{? = call Test_f(?,?,?)}");
callableDBUtil.registerOutParameter(1, java.sql.Types.INTEGER);
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt(2, 10);
callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(4, java.sql.Types.VARCHAR);
Test_f tets = (Test_f)callableDBUtil.executeCallableForObject(Test_f.class);
// System.out.println("name1:" + callableDBUtil.getString("name"));
// System.out.println("name2:" + callableDBUtil.getString("name1"));
System.out.println("Test_f is " + tets);
callableDBUtil.executeInsert("insert into test(id,name) values('11','name11')");
if(i == 0)
tm.rollback();
else
tm.commit();
}
catch(Exception e)
{
try {
tm.rollback();
} catch (RollbackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}
public static void main(String[] args)
{
System.out.println("1------------------------------------------testTest_fWithNameIndexForObject()");
testTest_fWithNameIndexForObject();
System.out.println("2------------------------------------------testTest_fWithNameIndexForObjectTx(1)");
testTest_fWithNameIndexForObjectTx(1);
System.out.println("3------------------------------------------testTest_fWithPositionIndex()");
testTest_fWithPositionIndex();
System.out.println("4------------------------------------------testTest_fWithNameIndexForXMLString()");
testTest_fWithNameIndexForXMLString();
System.out.println("5------------------------------------------testTest_fWithNameIndexForXMLStringRowHandler()");
testTest_fWithNameIndexForXMLStringRowHandler();
CallableDBUtil.debugStatus();
}
}
저장 프로세스 실행 실례:
package com.frameworkset.common;
import java.sql.SQLException;
import javax.transaction.RollbackException;
import com.frameworkset.common.poolman.CallableDBUtil;
import com.frameworkset.common.poolman.PreparedDBUtil;
import com.frameworkset.common.poolman.Record;
import com.frameworkset.common.poolman.handle.RowHandler;
import com.frameworkset.common.poolman.util.SQLResult;
import com.frameworkset.orm.transaction.TransactionManager;
public class TestCallableDBUtil {
public static void testTest_pWithPositionIndex()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
// callableDBUtil.execute("{call test_p(1,'ss',3,4)}");
callableDBUtil.prepareCallable("{call test_p(?,?,?,?)}");
callableDBUtil.setInt(1, 10);
callableDBUtil.registerOutParameter(2, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter(4, java.sql.Types.INTEGER);
callableDBUtil.executeCallable();
System.out.println("name1:" + callableDBUtil.getString(2));
System.out.println("name2:" + callableDBUtil.getString(3));
System.out.println("test:" + callableDBUtil.getInt(4));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void testTest_pWithNameIndex()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{call test_p(?,?,?,?)}");
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
callableDBUtil.executeCallable();
System.out.println("name1:" + callableDBUtil.getString("name"));
System.out.println("name2:" + callableDBUtil.getString("name1"));
System.out.println("test:" + callableDBUtil.getInt("test"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void testTest_pWithNameIndexForXMLString()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{call test_p(?,?,?,?,?)}");
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
callableDBUtil.registerOutParameter("nomatch", java.sql.Types.INTEGER);
String xmlString = callableDBUtil.executeCallableForXML();
System.out.println("xmlString:" + xmlString);
// System.out.println("name1:" + callableDBUtil.getString("name"));
// System.out.println("name2:" + callableDBUtil.getString("name1"));
// System.out.println("test:" + callableDBUtil.getInt("test"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void testTest_pWithNameIndexForXMLStringRowHandler()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{call test_p(?,?,?,?)}");
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
String xmlString = callableDBUtil.executeCallableForXML(new com.frameworkset.common.poolman.handle.RowHandler()
{
/**
*
* @param rowValue
*/
public void handleRow(Object rowValue,Record origine)
{
Object objects = (Object)rowValue;
System.out.println("objects rowhandler:" + objects);
// System.out.println("objects【0】:" + objects[0]);
// System.out.println(objects[1]);
}
});
System.out.println("name1:" + callableDBUtil.getString("name"));
System.out.println("name2:" + callableDBUtil.getString("name1"));
System.out.println("xmlString:" + xmlString);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void testTest_pWithNameIndexForObject()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{call test_p(?,?,?,?,?)}");
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
callableDBUtil.registerOutParameter("nomatch", java.sql.Types.INTEGER);
Test_p tets = (Test_p)callableDBUtil.executeCallableForObject(Test_p.class);
System.out.println("Test_p is " + tets);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void testoldMethod()
{
PreparedDBUtil callableDBUtil = new PreparedDBUtil();
try {
SQLResult result = callableDBUtil.execute("select * from tableinfo");
System.out.println(result.size());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void testTest_pWithNameIndexForObjectWithRowHandler()
{
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{call test_p(?,?,?,?)}");
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
Test_p tets = (Test_p)callableDBUtil.executeCallableForObject(Test_p.class,new RowHandler(){
public void handleRow(Object rowValue, Record record) {
Test_p test_p = (Test_p)rowValue;
try {
test_p.setTest(record.getString("test")+" ");
test_p.setName1(record.getString("name1"));
test_p.setName(record.getString("name"));
} catch (SQLException e) {
e.printStackTrace();
}
}
});
// System.out.println("name1:" + callableDBUtil.getString("name"));
// System.out.println("name2:" + callableDBUtil.getString("name1"));
System.out.println("Test_p is " + tets);
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
* / / 、 , poolman
* ; / / ,
* 。
* @param i 0 ,1
*/
public static void testTest_pWithNameIndexForObjectTx(int i)
{
TransactionManager tm = new TransactionManager();
try
{
tm.begin();
CallableDBUtil callableDBUtil = new CallableDBUtil();
callableDBUtil.prepareCallable("{call test_p(?,?,?,?)}");
// : Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
Test_p tets = (Test_p)callableDBUtil.executeCallableForObject(Test_p.class);
System.out.println("name1:" + callableDBUtil.getString("name"));
System.out.println("name2:" + callableDBUtil.getString("name1"));
System.out.println("Test_p is " + tets);
callableDBUtil.executeInsert("insert into test(id,name) values('11','name11')");
if(i == 0)
tm.rollback();
else
tm.commit();
}
catch(Exception e)
{
try {
tm.rollback();
} catch (RollbackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}
public static void main(String[] args)
{
// System.out.println("1---------------------------------------------------testTest_pWithPositionIndex()");
// testTest_pWithPositionIndex();
// System.out.println("2---------------------------------------------------testTest_pWithNameIndex()");
// testTest_pWithNameIndex();
// System.out.println("3---------------------------------------------------testTest_pWithNameIndexForObject()");
// testTest_pWithNameIndexForObject();
// System.out.println("4---------------------------------------------------testTest_pWithNameIndexForObjectTx()");
// testTest_pWithNameIndexForObjectTx(0);
// System.out.println("5---------------------------------------------------testTest_pWithNameIndexForXMLString()");
// testTest_pWithNameIndexForXMLString();
// System.out.println("6---------------------------------------------------testTest_pWithNameIndexForXMLStringRowHandler()");
// testTest_pWithNameIndexForXMLStringRowHandler();
// System.out.println("7---------------------------------------------------testTest_pWithNameIndexForObjectWithRowHandler()");
// testTest_pWithNameIndexForObjectWithRowHandler();
// CallableDBUtil.debugStatus();
// testoldMethod();
testTest_pWithNameIndexForXMLString();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Java 호출 Oracle 스토리지 프로세스 상세 정보Java 호출 Oracle 스토리지 프로세스 상세 정보 단계: 1. Oracle 스토리지 프로세스 작성 2. 데이터베이스 작성 연결 도구 클래스 얻기 3. 간단한 응용 프로그램 호출 저장 프로세스 작성 구현: 1. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.