| Author |
Poblem with Callable Statement
|
Ramesh Pappala
Ranch Hand
Joined: Sep 14, 2005
Posts: 50
|
|
Hi, I am trying to call a procedure through JDBC programming. This is the code I wrote : Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); con=DriverManager.getConnection ("jdbc:microsoft:sqlserver://ServerName:1433;SelectMethod=cursor;DatabaseName=databasename","username","password"); stmt = con.prepareCall("{call procedurename(?)"); stmt.setInt(1,15839401); boolean result = stmt.execute(); But I am getting the following exception : java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(Unknown Source) at com.microsoft.jdbc.base.BaseSQLStringGenerator.generateSQL(Unknown Source) at com.microsoft.jdbc.base.BaseSQL.getVerb(Unknown Source) at com.microsoft.jdbc.base.BaseSQL.resultType(Unknown Source) at com.microsoft.jdbc.base.BaseSQL.processSQL(Unknown Source) at com.microsoft.jdbc.base.BaseSQL.<init>(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.preProcessSQL(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown Source) at com.microsoft.jdbc.base.BaseCallableStatement.<init>(Unknown Source) at com.microsoft.jdbc.base.BaseConnection.prepareCall(Unknown Source) at com.microsoft.jdbc.base.BaseConnection.prepareCall(Unknown Source) at ThinDriversForSqlServer.main(ThinDriversForSqlServer.java:16) java.lang.NullPointerException at ThinDriversForSqlServer.main(ThinDriversForSqlServer.java:35) Can anyone tell what the problem was.
|
 |
Muhammad Saifuddin
Ranch Hand
Joined: Dec 06, 2005
Posts: 1318
|
|
what database you are using ? Did you Set the jar file in your classpath before running this code?
|
Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
|
 |
Muhammad Saifuddin
Ranch Hand
Joined: Dec 06, 2005
Posts: 1318
|
|
is a best practice to using try catch block around in connection code to know the specific area where exception is occured.
|
 |
Ramesh Pappala
Ranch Hand
Joined: Sep 14, 2005
Posts: 50
|
|
Hi Saif, I am using the data base SQL Server 2000, we can know that by seeing the class name given in the statement Class.forName("....."); Coming to my code I placed the above mentioned code in try block and I kept catch and finally also. I think pasting all the code is not good, that's why I didn't copied the complete program. So, every thing is fine in my code but I am getting that exception. Could you know the reason why it is giving that exception. The below one is the complete code : import java.sql.*; class ThinDriversForSqlServer { public static void main(String[] args) { Connection con=null; CallableStatement stmt = null; ResultSet rs=null; try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); con=DriverManager.getConnection("jdbc:microsoft:sqlserver://serverName:1433;SelectMethod=cursor;DatabaseName=databasename","username","password"); stmt = con.prepareCall("{call deleteDeliveryTicketDetails(?)"); stmt.setInt(1,15839401); boolean result = stmt.execute(); System.out.println("Delete Delivery Ticket Status................. : "+result); } catch(Exception e) { e.printStackTrace(); } finally { try { rs.close(); stmt.close(); con.close(); } catch(Exception e) { e.printStackTrace(); } } } }
|
 |
Muhammad Saifuddin
Ranch Hand
Joined: Dec 06, 2005
Posts: 1318
|
|
Originally posted by Ramesh Pappala: stmt = con.prepareCall("{call deleteDeliveryTicketDetails(?)");
closing curly brace is missing in you call procedure statement. [ January 15, 2007: Message edited by: Saif uddin ]
|
 |
 |
|
|
subject: Poblem with Callable Statement
|
|
|