Solved

Help needed using JDBC with MS SQL Server 2000

Posted on 2002-03-12
3
216 Views
Last Modified: 2010-03-31
I've probably used stored procedures a 1,000 times before with other JDBC drivers and had no problems.  Now I'm building an application that interfaces with SQL Server 2000 and need to use some stored procedures that return not only a ResultSet, but a out parameter as well.  My Java method starts off like this:

    public synchronized ArrayList getValuationEOD(String accountName, Date date) throws SQLException
    {
        valSummaryStmt.clearParameters();
        valSummaryStmt.setString(2, accountName);

        String dateYMD = Utils.formatDateYMD(date);
        valSummaryStmt.setString(3, dateYMD);

        valSummaryStmt.registerOutParameter(1, BaseData.INTEGER);
        ResultSet rs = valSummaryStmt.executeQuery();
        int rowCount = rs.getInt(1);

        // Create ArrayList of ValuationSummary objects (with ValuationContractDetail object)
        ArrayList list = new ArrayList();

        // return with an empty ArrayList if there were no records returned; DO NOT PROCESS
        // FURTHER!!!
        if (rowCount == 0) return list;

        ValuationSummary vs = null;
        while (rs.next()) {
           // ... do something with the data
        }
        rs.close();

        return list;
     }

where BaseData is in the package com.microsoft.jdbc.base
and the property valSummaryStr is defined as:

    private final String valSummaryStr = "{?=call dbo.LOTS_GetValuationEOD(?, ?)}";

NOTE: I did a prepareCall(valSummaryStr) before I call the method above.

Upon executing the query, I get the following error:

java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]Invalid parameter bindi
ng(s).
        at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
)
        at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
        at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unkn
own Source)
        at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unkn
own Source)
        at com.microsoft.jdbc.base.BasePreparedStatement.preImplExecute(Unknown
Source)
        at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown So
urce)
        at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown So
urce)
        at weblogic.jdbc20.pool.PreparedStatement.executeQuery(PreparedStatement
.java:35)
        at weblogic.jdbc20.rmi.internal.PreparedStatementImpl.executeQuery(Prepa
redStatementImpl.java:46)
        at weblogic.jdbc20.rmi.SerialPreparedStatement.executeQuery(SerialPrepar
edStatement.java:40)
        at com.commerzbank.util.SQLManager.getValuationEOD(SQLManager.java:379)
        at com.commerzbank.reportsdata.ValuationReportData.getValuationEOD(Valua
tionReportData.java:131)
        at com.commerzbank.reportsdata.LOTSUserBean.getValuationEOD(LOTSUserBean
.java:101)
        at jsp_servlet.__test._jspService(__test.java:113)
        at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:120)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:138)
        at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:941)
        at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:905)
        at weblogic.servlet.internal.ServletContextManager.invokeServlet(Servlet
ContextManager.java:269)
        at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.jav
a:391)
        at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:273)

        at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)

Where are the JDBC Types defined for the MS drivers? Are there any other problems with the way I'm doing this?  

All help will be greatly appreciated.

0
Comment
Question by:mwalker
  • 2
3 Comments
 

Author Comment

by:mwalker
ID: 6858341
I'm now trying to declare the call String as
    private final String valSummaryStr = "{?=call dbo.LOTS_GetValuationEOD(?, ?, ?)}";

where the third parameter is the parameter that I want to retrieve as my out parameter (the third parameter to the stored procedure is declared as an OUTPUT parameter).

Thanks again for any help.
0
 
LVL 1

Accepted Solution

by:
gigsvoo earned 200 total points
ID: 6859155
Try this:

private final String valSummaryStr("{begin call dbo.LOTS_GetValuationEOD(?,?,?); END;}");

I had the same problem with u earlier...
0
 

Author Comment

by:mwalker
ID: 6910900
Sorry it took so long to try your solution.  It worked!  Thanks.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now