Re: Error when binding value to prepared statement with SQL Server 2005

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello Arto, Joe,

I have reproduced the problem and filed a bug. Thank you for reporting the
issue.

Thanks,
Kamil

Kamil Sykora [MSFT]
Microsoft Developer Support - Webdata

This posting is provided "AS IS", with no warranties, and confers no
rights.

Please do not send email directly to this alias. This alias is for
newsgroup
purposes only.
--------------------
| Date: Tue, 29 Nov 2005 08:39:31 -0800
| From: Joe Weinstein <joeNOSPAM@xxxxxxx>
| Subject: Re: Error when binding value to prepared statement with SQL
Server
| 2005
|
|
|
| Arto Basmadjian wrote:
|
| > Joe I had to adjust your program slightly to get it to work
| > (dd.getDatabaseMajorVersion() & dd.getDatabaseMinorVersion() are not
| > available to me, so I substituted...)
| >
| > Anyhow... I still get the same error
| >
| > From the results, looks like you are not using sqlServer 2005, nor the
| > latest(beta2) jdbc driver.
|
| Ok, that indicates the bug is in the later
| driver version. MS will take it from here
| I'm sure.
|
| Joe Weinstein at BEA Systems
|
| >
| > Results...
| > Database version is 9.0.1399
| > Driver version is 1.0.419.102
| > Col count is 2
| > Col 1 is 'bar'
| > Col 2 is 'schmeck'
| > 'qwe' 'qweqwe'
| > com.microsoft.sqlserver.jdbc.SQLServerException: Index out of range1
Valid
| > range is 1 to 0
| > at
| >
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown
| > Source)
| > at com.microsoft.sqlserver.jdbc.SQLServerStatement.setParam(Unknown
Source)
| > at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setString(Unknown
| > Source)
| > at com.tecsys.base.foo.main(foo.java:46)
| >
| >
| > Arto
| >
| > "Joe Weinstein" <joeNOSPAM@xxxxxxx> wrote in message
| > news:ewoHhDH9FHA.2716@xxxxxxxxxxxxxxxxxxxxxxx
| >
| >>
| >>Arto Basmadjian wrote:
| >>
| >>
| >>>I'm using the latest (beta 2) jdbc driver to connect to an Sql Express
| >>>2005 database.
| >>>
| >>>I'm preparing the following sql statement:
| >>>
| >>>SELECT md_database.database_name, md_database.desc_key,
| >>>md_database.mod_counter, '' data_model FROM md_database WHERE
| >>>md_database.database_name = ?
| >>>(note that its 2 single quotes just before data_model)
| >>>
| >>>When I try to bind the value for database_name using:
| >>>ppdStmt.setString(1, "meta");
| >>>
| >>>I get the following error:
| >>>com.microsoft.sqlserver.jdbc.SQLServerException: Index out of range1
| >>>Valid range is 1 to 0
| >>>
| >>>The same code works fine using Sql Server 2000 (with its matching jdbc
| >>>driver(s) & connection string). If I use the new 2005 jdbc driver to
| >>>connect to the Sql Server 2000 database, I also get the error.
| >>>
| >>>If I change my sql, and use any constant (other than an empty string),
it
| >>>works fine. For example, doing the same bind on the following sql:
| >>>SELECT md_database.database_name, md_database.desc_key,
| >>>md_database.mod_counter, 'DontCare' data_model FROM md_database WHERE
| >>>md_database.database_name = ?
| >>>works fine.
| >>>
| >>>Any ideas? driver bug?
| >>>
| >>>Arto
| >>
| >>Hi Arto.
| >>I can't reproduce the problem. Here's a program to try. I get the
output:
| >>
| >>C:\new_ms_driver>java foo
| >>Driver version is 1.0.107.104
| >>Database Major version is 8
| >>Database Minor version is 0
| >>Col count is 2
| >>Col 1 is 'bar'
| >>Col 2 is 'schmeck'
| >>'qwe' 'qweqwe'
| >>Col count is 2
| >>Col 1 is 'bar'
| >>Col 2 is 'schmeck'
| >>'qwe' ''
| >>
| >>import java.sql.*;
| >>import java.util.*;
| >>
| >>public class foo
| >>{
| >> public static void main(String args[])
| >> throws Exception
| >> {
| >> Connection c = null;
| >> try
| >> {
| >> Properties props = new Properties();
| >> Driver d = new com.microsoft.sqlserver.jdbc.SQLServerDriver();
| >>
| >> props.put("user", "joe");
| >> props.put("password", "joe");
| >>
| >> c = d.connect("jdbc:sqlserver://joe:1433", props );
| >>
| >> DatabaseMetaData dd = c.getMetaData();
| >> System.out.println("Driver version is " +
| >>dd.getDriverVersion() );
| >> System.out.println("Database Major version is " +
| >>dd.getDatabaseMajorVersion() );
| >> System.out.println("Database Minor version is " +
| >>dd.getDatabaseMinorVersion() );
| >>
| >> Statement s = c.createStatement();
| >> try { s.executeUpdate("drop table joetable"); } catch
(Exception
| >>ignore){}
| >>
| >> s.executeUpdate("create table joetable (bar varchar(30) not
| >>null)");
| >> s.executeUpdate("insert into joetable values('qwe')");
| >>
| >> PreparedStatement ps = c.prepareStatement("select bar,
'qweqwe'
| >>schmeck from joetable where bar = ?");
| >> ps.setString(1, "qwe");
| >> ResultSet r = ps.executeQuery();
| >> ResultSetMetaData rm = r.getMetaData();
| >>
| >> System.out.println("Col count is " + rm.getColumnCount() );
| >> System.out.println("Col 1 is '" + rm.getColumnName(1) + "'");
| >> System.out.println("Col 2 is '" + rm.getColumnName(2) + "'");
| >> while (r.next()) System.out.println("'" + r.getString(1) + "'
'"
| >>+ r.getString(2) + "'" );
| >>
| >> PreparedStatement ps2 = c.prepareStatement("select bar, ''
| >>schmeck from joetable where bar = ?");
| >> ps2.setString(1, "qwe");
| >> ResultSet r2 = ps2.executeQuery();
| >> ResultSetMetaData rm2 = r2.getMetaData();
| >> System.out.println("Col count is " + rm2.getColumnCount() );
| >> System.out.println("Col 1 is '" + rm2.getColumnName(1) + "'");
| >> System.out.println("Col 2 is '" + rm2.getColumnName(2) + "'");
| >> while (r2.next()) System.out.println( "'" + r2.getString(1) +
"'
| >>'" + r2.getString(2) + "'");
| >> }
| >> catch(Exception exception1)
| >> {
| >> exception1.printStackTrace();
| >> }
| >> finally
| >> {
| >> if (c != null) try {c.close();} catch (Exception ignore){}
| >> }
| >> }
| >>}
| >>
| >
| >
| >
|
|

.



Relevant Pages

  • cvs-src summary for May 31 - June 7
    ... You can get old summaries, and an HTML version of this one, at ... driver for Intel Ethernet cards, then the ndis driver, for emulation of ... Maxime Henrion changed the fxp driver to use the device sysctl tree, ... This bug is covered by `FreeBSD-SA-04:12.jailroute`_, ...
    (freebsd-current)
  • Re: Cannot display ODBC login prompt - want to connect without DSN
    ... database without knowing anything beforehand except the driver name. ... need a connection string and different data sources use different connection ... ODBC, ADO, and VB Script. ...
    (microsoft.public.dotnet.framework.adonet)
  • cvs-src summary for May 24-31
    ... Tony Ackerman committed the first release of the ixgb driver, ... Brooks Davis added support for a /etc/eui64 file, ... Oliver Eikemeier added a "-depth n" flag to find. ... Dag-Erling Smorgrav fixed a bug in the msync system call that permitted ...
    (freebsd-current)
  • Re: JDBC URL for Oracle Database With Failover (2 db servers)
    ... After you've loaded the driver, you can establish a connection using ... each form requires a database URL. ... For Oracle, the database URL has ...
    (comp.lang.java.databases)
  • RE: New JDBC 1.2 driver runs slower than JDBC 1.1; my db definitio
    ... If the support incident ends up verifying a slowdown in the new driver, ... New JDBC 1.2 driver runs slower than JDBC 1.1; ... I do think this would happen in general, not just for my database; ...
    (microsoft.public.sqlserver.jdbcdriver)