• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Poblem with Callable Statement

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what database you are using ?
Did you Set the jar file in your classpath before running this code?
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic