本文整理汇总了Java中java.sql.CallableStatement.getParameterMetaData方法的典型用法代码示例。如果您正苦于以下问题:Java CallableStatement.getParameterMetaData方法的具体用法?Java CallableStatement.getParameterMetaData怎么用?Java CallableStatement.getParameterMetaData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.CallableStatement
的用法示例。
在下文中一共展示了CallableStatement.getParameterMetaData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParameterParser
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* Tests the new parameter parser that doesn't require "BEGIN" or "\n" at
* end of parameter declaration
*
* @throws Exception
*/
public void testParameterParser() throws Exception {
if (!versionMeetsMinimum(5, 0)) {
return;
}
CallableStatement cstmt = null;
try {
createTable("t1", "(id char(16) not null default '', data int not null)");
createTable("t2", "(s char(16), i int, d double)");
createProcedure("foo42", "() insert into test.t1 values ('foo', 42);");
this.conn.prepareCall("{CALL foo42()}");
this.conn.prepareCall("{CALL foo42}");
createProcedure("bar", "(x char(16), y int, z DECIMAL(10)) insert into test.t1 values (x, y);");
cstmt = this.conn.prepareCall("{CALL bar(?, ?, ?)}");
ParameterMetaData md = cstmt.getParameterMetaData();
assertEquals(3, md.getParameterCount());
assertEquals(Types.CHAR, md.getParameterType(1));
assertEquals(Types.INTEGER, md.getParameterType(2));
assertEquals(Types.DECIMAL, md.getParameterType(3));
createProcedure("p", "() label1: WHILE @a=0 DO SET @a=1; END WHILE");
this.conn.prepareCall("{CALL p()}");
createFunction("f", "() RETURNS INT NO SQL return 1; ");
cstmt = this.conn.prepareCall("{? = CALL f()}");
md = cstmt.getParameterMetaData();
assertEquals(Types.INTEGER, md.getParameterType(1));
} finally {
if (cstmt != null) {
cstmt.close();
}
}
}
示例2: testBug84324
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* Tests fix for Bug#84324 - CallableStatement.extractProcedureName() not work when catalog name with dash.
*/
public void testBug84324() throws Exception {
createDatabase("`testBug84324-db`");
/*
* Test procedure.
*/
createProcedure("`testBug84324-db`.`testBug84324-proc`", "(IN a INT, INOUT b VARCHAR(100)) BEGIN SELECT a, b; END");
final CallableStatement cstmtP = this.conn.prepareCall("CALL testBug84324-db.testBug84324-proc(?, ?)");
ParameterMetaData pmd = cstmtP.getParameterMetaData();
assertEquals(2, pmd.getParameterCount());
// 1st parameter
assertEquals("INT", pmd.getParameterTypeName(1));
assertEquals(Types.INTEGER, pmd.getParameterType(1));
assertEquals(Integer.class.getName(), pmd.getParameterClassName(1));
assertEquals(ParameterMetaData.parameterModeIn, pmd.getParameterMode(1));
// 2nd parameter
assertEquals("VARCHAR", pmd.getParameterTypeName(2));
assertEquals(Types.VARCHAR, pmd.getParameterType(2));
assertEquals(String.class.getName(), pmd.getParameterClassName(2));
assertEquals(ParameterMetaData.parameterModeInOut, pmd.getParameterMode(2));
cstmtP.setInt(1, 1);
cstmtP.setString(2, "foo");
assertThrows(SQLException.class, new Callable<Void>() {
public Void call() throws Exception {
cstmtP.execute();
return null;
}
}); // Although the procedure metadata could be obtained, the end query actually fails due to syntax errors.
cstmtP.close();
/*
* Test function.
*/
createFunction("`testBug84324-db`.`testBug84324-func`", "(a INT, b VARCHAR(123)) RETURNS INT BEGIN RETURN a + LENGTH(b); END");
final CallableStatement cstmtF = this.conn.prepareCall("{? = CALL testBug84324-db.testBug84324-func(?, ?)}");
pmd = cstmtF.getParameterMetaData();
assertEquals(3, pmd.getParameterCount());
// 1st parameter
assertEquals("INT", pmd.getParameterTypeName(1));
assertEquals(Types.INTEGER, pmd.getParameterType(1));
assertEquals(Integer.class.getName(), pmd.getParameterClassName(1));
assertEquals(ParameterMetaData.parameterModeOut, pmd.getParameterMode(1));
// 2nd parameter
assertEquals("INT", pmd.getParameterTypeName(2));
assertEquals(Types.INTEGER, pmd.getParameterType(2));
assertEquals(Integer.class.getName(), pmd.getParameterClassName(2));
assertEquals(ParameterMetaData.parameterModeIn, pmd.getParameterMode(2));
// 3rd parameter
assertEquals("VARCHAR", pmd.getParameterTypeName(3));
assertEquals(Types.VARCHAR, pmd.getParameterType(3));
assertEquals(String.class.getName(), pmd.getParameterClassName(3));
assertEquals(ParameterMetaData.parameterModeIn, pmd.getParameterMode(3));
cstmtF.registerOutParameter(1, Types.INTEGER);
cstmtF.setInt(2, 1);
cstmtF.setString(3, "foo");
assertThrows(SQLException.class, new Callable<Void>() {
public Void call() throws Exception {
cstmtF.execute();
return null;
}
}); // Although the function metadata could be obtained, the end query actually fails due to syntax errors.
cstmtP.close();
cstmtF.close();
}
示例3: testBug84324
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* Tests fix for Bug#84324 - CallableStatement.extractProcedureName() not work when catalog name with dash.
*/
public void testBug84324() throws Exception {
createDatabase("`testBug84324-db`");
/*
* Test procedure.
*/
createProcedure("`testBug84324-db`.`testBug84324-proc`", "(IN a INT, INOUT b VARCHAR(100)) BEGIN SELECT a, b; END");
final CallableStatement cstmtP = this.conn.prepareCall("CALL testBug84324-db.testBug84324-proc(?, ?)");
ParameterMetaData pmd = cstmtP.getParameterMetaData();
assertEquals(2, pmd.getParameterCount());
// 1st parameter
assertEquals("INT", pmd.getParameterTypeName(1));
assertEquals(Types.INTEGER, pmd.getParameterType(1));
assertEquals(Integer.class.getName(), pmd.getParameterClassName(1));
assertEquals(ParameterMetaData.parameterModeIn, pmd.getParameterMode(1));
// 2nd parameter
assertEquals("VARCHAR", pmd.getParameterTypeName(2));
assertEquals(Types.VARCHAR, pmd.getParameterType(2));
assertEquals(String.class.getName(), pmd.getParameterClassName(2));
assertEquals(ParameterMetaData.parameterModeInOut, pmd.getParameterMode(2));
cstmtP.setInt(1, 1);
cstmtP.setString(2, "foo");
assertThrows(SQLException.class, new Callable<Void>() {
public Void call() throws Exception {
cstmtP.execute();
return null;
}
}); // Although the procedure metadata could be obtained, the end query actually fails due to syntax errors.
cstmtP.close();
/*
* Test function.
*/
createFunction("`testBug84324-db`.`testBug84324-func`", "(a INT, b VARCHAR(123)) RETURNS INT DETERMINISTIC BEGIN RETURN a + LENGTH(b); END");
final CallableStatement cstmtF = this.conn.prepareCall("{? = CALL testBug84324-db.testBug84324-func(?, ?)}");
pmd = cstmtF.getParameterMetaData();
assertEquals(3, pmd.getParameterCount());
// 1st parameter
assertEquals("INT", pmd.getParameterTypeName(1));
assertEquals(Types.INTEGER, pmd.getParameterType(1));
assertEquals(Integer.class.getName(), pmd.getParameterClassName(1));
assertEquals(ParameterMetaData.parameterModeOut, pmd.getParameterMode(1));
// 2nd parameter
assertEquals("INT", pmd.getParameterTypeName(2));
assertEquals(Types.INTEGER, pmd.getParameterType(2));
assertEquals(Integer.class.getName(), pmd.getParameterClassName(2));
assertEquals(ParameterMetaData.parameterModeIn, pmd.getParameterMode(2));
// 3rd parameter
assertEquals("VARCHAR", pmd.getParameterTypeName(3));
assertEquals(Types.VARCHAR, pmd.getParameterType(3));
assertEquals(String.class.getName(), pmd.getParameterClassName(3));
assertEquals(ParameterMetaData.parameterModeIn, pmd.getParameterMode(3));
cstmtF.registerOutParameter(1, Types.INTEGER);
cstmtF.setInt(2, 1);
cstmtF.setString(3, "foo");
assertThrows(SQLException.class, new Callable<Void>() {
public Void call() throws Exception {
cstmtF.execute();
return null;
}
}); // Although the function metadata could be obtained, the end query actually fails due to syntax errors.
cstmtP.close();
cstmtF.close();
}
示例4: setProcedure
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* @param procedure The procedure to set.
* @param columns columns
* @exception Exception Description of Exception
*/
public void setProcedure(String procedure, ArrayList columns) throws Exception {
if (isconfigured) { return; }
if (poolConnectionHandler != null) {
con = poolConnectionHandler.getConnection();
if (!isConnected()) { throw new Exception(
"JDBCLogger::setProcedure(), Given connection isnt connected to database !"); }
}
this.procedure = procedure;
// prepare call
CallableStatement cStmt = this.createCallableStatement(columns.size());
JDBCLogColumn logcol;
ParameterMetaData pmd;
// 2.6.2005 jschmied
// ParameterMetaData is supported on different levels by Oracle
try {
// J2SDK 1.4+; limited support by Oracle drivers 10.x and 9.x
pmd = cStmt.getParameterMetaData();
num = pmd.getParameterCount();
if (num >= 1) {
// oracle 10.1.0.4 has some stubs in ParameterMetaData,
// try if a function throws a UnsupportedFeature exception
pmd.getParameterType(1);
pmd.getParameterTypeName(1);
pmd.isNullable(1);
}
} catch (Exception e) {
pmd = null;
num = columns.size();
}
logcols = new ArrayList(num);
for (int i = 1; i <= num; i++) {
logcol = new JDBCLogColumn();
JDBCColumnStorage col = (JDBCColumnStorage) columns.get(i - 1);
logcol.name = col.column.toUpperCase();
if (pmd == null) {
logcol.type = col.type;
logcol.sqlType = col.sqlType;
logcol.nullable = true; // assume true
} else {
logcol.type = pmd.getParameterTypeName(i);
logcol.sqlType = pmd.getParameterType(i);
logcol.nullable = (pmd.isNullable(i) == ParameterMetaData.parameterNullable);
}
logcol.isWritable = true;
logcols.add(logcol);
}
cStmt.close();
freeConnection();
isconfigured = true;
}