select GUID -> numeric value out of range

  • Hello, I am having a weird problem in ms sql server 2005 where I do a statement, for each table in a list of table names, similar to the following:

    SELECT top 1 * FROM dbo.

    this works perfectly for most of the tables, except for some tables containing a field used to store a GUID - it is declared as a Datatype = UniqueIdentifier, and with a length of 16;

    it fails with the following exception: (code written in java)

    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver] Numeric value out of range

    I sincerely hope someone can give me some insight into this problem, and how to solve it. 🙂

  • Could you post the java code please? The SQL looks ok, but it would be useful to know what the java code is doing also.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hello Gail,

    thanks for your interest. I have a procedure with an incoming resultset(rs)

    then I would like to get all the column names of the particular table, tab separate it, into a list, and the same for the actual values. In the end I want to loop thru the list, printing out the column names and resulted values into a text file. This works for other tables not having the GUID; I am VERY sure it has to be connected to the GUID....

    😉

    =======================================================

    String str1 = "";

    String str2 = "";

    List list = new LinkedList();

    ResultSetMetaData md = rs.getMetaData();

    int cols = md.getColumnCount();

    for (int i = 1; i <= cols; i++) {

    str1 = str1 + md.getColumnName(i) + "\t";

    }

    list.add(str1);

    // add the column values to the list

    while (rs.next()) {

    str2 = "";

    for(int i = 1; (i <= cols); i++){

    str2 = str2 + rs.getString(i) + "\t";

    }

    list.add(str2);

    }

    =======================================================

  • Can you also post the java code where you create and open the result set?

    What's tha data type of rs? SQLServerResultSet?

    Which line throws the error?

    Is your linked list just a java.util.LinkedList?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Are you sure that rs.getString(i) on the guid column is causing it? I guess I mean, is there another layer of abstraction between you and the DB where it may get converted into an int and throw the error?

  • Hi! Please someone help me too.. I've the same problem 🙁

    I use a ResultSet to query the table.

    java.sql.PreparedStatement ps = conn.prepareStatement("SELECT FORUM_ID, USER_ID FROM forum_users where id="

    + "?");

    ps.setString(1, key);

    rs = ps.executeQuery();

    while (rs.next())

    {

    string forumId = rs.getString(1);

    }

    Any suggest?

  • Please post new questions in a new thread. Thanks.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply