0
我想從Java程序調用Teradata存儲過程,任何人都可以使用示例java程序嗎?示例Java程序調用Teradata存儲過程
由於受到一些限制,我無法在Teradata內部創建一些UDF函數,因此我在Teradata中開發了這些函數作爲存儲過程。
現在,我需要使用Java程序調用這些過程。
朋友,這是我的java程序,
public static String executeme(String x,String y) throws SQLException, ClassNotFoundException
{
System.out.println(" Message: 2 ");
String connectionString = "jdbc:teradata://192.168.0.0/xyz,tmode=ANSI,charset=UTF8,DBS_PORT=1025,DATABASE=xyz";
String user = "xyz";
String passwd = "xxx";
System.out.println(" Message: 3 after url " +x);
String sCall = "{CALL "+x+"(?,?)}";
System.out.println(" Message: after call str " +sCall);
String result = null;
try
{
Class.forName("com.teradata.jdbc.TeraDriver");
Connection con = DriverManager.getConnection(connectionString, user, passwd);
System.out.println(" Message: after con "+con );
CallableStatement cStmt = con.prepareCall(sCall);
cStmt.setString(1, y);
cStmt.registerOutParameter(2, Types.VARCHAR);
result = cStmt.getString(2);
return result;
}
catch(ClassNotFoundException e)
{
System.out.println(" Message: " + e);
return e.toString();
}
}
public static void main(String[] args) throws SQLException, ClassNotFoundException {
// TODO Auto-generated method stub
String outs=null;
System.out.println(" Message: 1 ");
outs = testing.executeme("sample_name", "ABCD");
System.out.println(outs);
}
但是,運行該程序時,我得到的錯誤:
Message: 1
Message: 2
Message: 3 after url ment_f_swithin
Message: after con [email protected]
Exception in thread "main" java.sql.SQLException: [Teradata Database] [TeraJDBC 14.10.00.42] [Error 5510] [SQLState HY000] Invalid session mode for procedure execution.
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDatabaseSQLException (ErrorFactory.java:308)
at com.teradata.jdbc.jdbc_4.statemachine.ReceiveInitSubState.action(ReceiveInitSubState.java:109)
at com.teradata.jdbc.jdbc_4.statemachine.StatementReceiveState.subStateMachine(StatementReceiveState.java:307)
at com.teradata.jdbc.jdbc_4.statemachine.StatementReceiveState.action(StatementReceiveState.java:196)
at com.teradata.jdbc.jdbc_4.statemachine.StatementController.runBody(StatementController.java:123)
at com.teradata.jdbc.jdbc_4.statemachine.StatementController.run(StatementController.java:114)
at com.teradata.jdbc.jdbc_4.TDStatement.executeStatement(TDStatement.java:386)
at com.teradata.jdbc.jdbc_4.TDStatement.prepareRequest(TDStatement.java:573)
at com.teradata.jdbc.jdbc_4.TDPreparedStatement.<init>(TDPreparedStatement.java:117)
at com.teradata.jdbc.jdk6.JDK6_SQL_PreparedStatement.<init>(JDK6_SQL_PreparedStatement.java:29)
at com.teradata.jdbc.jdk6.JDK6_SQL_CallableStatement.<init>(JDK6_SQL_CallableStatement.java:23)
at com.teradata.jdbc.jdk6.JDK6_SQL_Connection.constructCallableStatement(JDK6_SQL_Connection.java:87)
at com.teradata.jdbc.jdbc_4.TDSession.prepareCall(TDSession.java:1373)
at com.teradata.jdbc.jdbc_4.TDSession.prepareCall(TDSession.java:1408)
at com.teradata.jdbc.jdbc_4.TDSession.prepareCall(TDSession.java:1394)
at java_func.testing.executeme(testing.java:32)
at java_func.testing.main(testing.java:55)
我試着使用所有3種模式ANSI,TERA ,BTET。而我依然得到相同的錯誤,請指點我請
哪裏是你的代碼示例?請粘貼它來獲得幫助。 –
您是否閱讀過在線文檔? https://developer.teradata.com/doc/connectivity/jdbc/reference/current/samplePrograms.html – dnoeth
[從Java/JPA調用存儲過程]的可能重複(http://stackoverflow.com/questions/3572626/calling -stored-程序從 - java的JPA) – david