Solved

Help needed using JDBC with MS SQL Server 2000

Posted on 2002-03-12
3
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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:
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.

628 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