Solved

Help needed using JDBC with MS SQL Server 2000

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Spring Framework HTTPSession management 1 36
MySQL  on Tomcat 8 47
jsp insert to database example 2 26
Crystal Reports Licensing Questions 4 13
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 …
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 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…
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.

831 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