I want to call Teradata store procedure from Java program, Can anyone have the sample java program ?
Due to some restriction,I couldn't create some UDF functions inside Teradata, so I developed those function as stored procedure in Teradata.
Now, I need to call those procedures using Java Program.
Friends, These is my java program,
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);
}
But, while running this program, i'm getting as error:
Message: 1
Message: 2
Message: 3 after url ment_f_swithin
Message: after con com.teradata.jdbc.jdk6.JDK6_SQL_Connection@85ede7b
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)
I tried using all the 3 modes ANSI,TERA,BTET. but still i'm getting the same error, kindly guide me please