Search code examples
jdbcsap-iq

JDBC connection to SAP/Sybase IQ with master-slave configuration failing


I am trying to connect to a SAP/Sybase IQ database that is running in a master-slave configuration. The connection works successfully when I connect to the master. For slaves, however, I am only able to connect when full-admin privileges (or SERVER OPERATOR, in Sybase terms) are assigned to the user I am using; without that I get "Login Failed" error. I have ensured that the username/password are correct and, in fact, they work well on the master.

I neither have the option to connect to the master nor can I get the full-admin privileges on a long term basis. Is there anything that I can do get my JDBC code to work with the slaves on this master-slave configuration? Below is my Java JDBC code, which is fairly standard.

import java.sql.*;

public class SybaseJDBCConnector {
   static final String JDBC_DRIVER = "com.sybase.jdbc4.jdbc.SybDriver";  
   static final String DB_URL = "jdbc:sybase:Tds:host:port/dbname";

   static final String USER = "username";
   static final String PASS = "password";

   public static void main(String[] args) {
   Connection conn = null;
   Statement stmt = null;
   try{
      Class.forName(JDBC_DRIVER);

      System.out.println("Connecting to database...");
      conn = DriverManager.getConnection(DB_URL,USER,PASS);
      System.out.println("Successfully connected");
      conn.close();
   }catch(SQLException se){
      se.printStackTrace();
   }catch(Exception e){
      e.printStackTrace();
   }finally{
      // do something
   }
 }
}

Solution

  • Adding charset=eucgb in db url will sole the issue. Example: "jdbc:sybase:Tds:host:port/dbname?charset=eucgb"