Solved

Help needed using JDBC with MS SQL Server 2000

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet filter example 37 83
web application structure 18 111
Tomcat: Unable to run tomcat service. 2 29
Problem to Alipay 10 67
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

756 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