Search code examples
javajdbcsybasejconnect

Error inserting in remote table using jconnect


When I do a insert in a remote tabke using jconnect it gives me the following error:

Unexpected exception : java.sql.SQLException: This transaction has been rolled back, rather than only the current statement.
, sqlstate = ZZZZZjava.sql.SQLException: This transaction has been rolled back, rather than only the current statement.

    at com.sybase.jdbc4.jdbc.SybConnection.getAllExceptions(SybConnection.java:2780)
    at com.sybase.jdbc4.jdbc.SybStatement.handleSQLE(SybStatement.java:2665)
    at com.sybase.jdbc4.jdbc.SybStatement.nextResult(SybStatement.java:295)
    at com.sybase.jdbc4.jdbc.SybStatement.nextResult(SybStatement.java:272)
    at com.sybase.jdbc4.jdbc.SybStatement.updateLoop(SybStatement.java:2515)
    at com.sybase.jdbc4.jdbc.SybStatement.executeUpdate(SybStatement.java:2499)
    at com.sybase.jdbc4.jdbc.SybStatement.executeUpdate(SybStatement.java:577)
    at connectSybase.main(connectSybase.java:48)

Do you know what it might be?

Here's my full code:

import java.io.*;
import java.sql.*;

public class connectSybase {

    public static void main(String args[])
    {
        try
        {
            // jconn3 <-- do pessoal do OMS
            //Class.forName("com.sybase.jdbc3.jdbc.SybDriver");

            // jconn4 <-- do servidor de OMS1_PAR_DEV_SQL
            Class.forName("com.sybase.jdbc4.jdbc.SybDriver");

        }
        catch (ClassNotFoundException cnfe)
        {
            System.out.println("BUM!");
        }
        try
        {
            System.out.println("Any of the following may throw an SQLException.");

            System.out.println("Opening a connection.");

            Connection con = java.sql.DriverManager.getConnection
                    ("----------------------------");
            // more code to use connection ...


            System.out.println("Creating a statement object.");

            Statement stmt = con.createStatement();

            System.out.println("Executing the query.");

            ResultSet rs = stmt.executeQuery("Select top 10 * from OMS_DEV..SCRIBE_AR");

            System.out.println("Process the result set.");

            while (rs.next())
            {
                System.out.println("Fetched value " + rs.getString(1));
            }

            System.out.println("Executing the query.");
            int result = stmt.executeUpdate("---------------");


            System.out.println("Process the result set: " + result );

        }

        catch (SQLException sqe)
        {
            sqe.printStackTrace();


            System.out.println("Unexpected exception : " +
                    sqe.toString() + ", sqlstate = " +
                    sqe.getSQLState());
            System.exit(1);
        }
        System.exit(0);
    }
}

I've omitted the insert and the connection but both work because I get the result of the first select (only the insert fails) and the insert is also correct because it works using isql or dbartisan.


Solution

  • Sybase error message was not specific but the problem was related to packet size. In ASE it was 8192 and in IQ only 2048.

    It generated the error when the packet exceeded 2k.