Dave
Dave

Reputation: 3

Invalid string or buffer length

JSP is a new world for me, but I need to make a small change in a web application. I've figured out how to do pretty much everything I need, but I'm having some problems getting data out of a database.

I'm using an example from here and I can get the following code to display the data:

  while(resultset.next()){
        out.println(resultset.getString(1));

  }

When I try assigning resultset.getString(1) to a variable, I get:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid string or buffer length

Here's a sample of the code that I'm using:

        <% 
      String strEmail = "";
      Connection connection = DriverManager.getConnection(
            "jdbc:odbc:dbcon", "acctName", "acctNamePass");

        Statement statement = connection.createStatement() ;
        ResultSet resultset = statement.executeQuery("SELECT  [ctt_email] FROM [petergriffin].[dbo].[contact] where ctt_id = 13") ; 

        while(resultset.next()){
            strEmail = resultset.getString(1);

        }
        out.println(strEmail);

    %>      

Can someone tell me what I'm doing wrong?

Upvotes: 0

Views: 11361

Answers (1)

JNevill
JNevill

Reputation: 50034

Despite it seeming like a datatype issue, this is a common error message if you are working on a 64 bit system using the jdbc/odbc bridge. If I'm not mistaken the jdbc:odbc bridge uses an older 32-bit ODBC driver which gets all janky when used in a 64 bit environment (which I'm guessing you are working in).

The recommendation is to find a more suitable and up-to-date JDBC driver like http://msdn.microsoft.com/en-us/data/aa937724.aspx

Upvotes: 1

Related Questions