Solved

Help needed using JDBC with MS SQL Server 2000

Posted on 2002-03-12
3
217 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

947 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

21 Experts available now in Live!

Get 1:1 Help Now