Pregunta

Soy nuevo en Java y estoy tratando de utilizar JDBC para conectarse a una base de datos universo. Estoy usando Sun Java JDK 6 a la utilización de NetBeans para construir el proyecto. Mi prueba simple continuación construye sin embargo, da los errores a continuación:

> run:
driver loaded
Exception in thread "main" java.lang.ExceptionInInitializerError
Connecting...
        at com.ibm.u2.jdbc.UniJDBCProtocolU2Impl.initDefaultMarks(UniJDBCProtocolU2Impl.java:1239)
        at com.ibm.u2.jdbc.UniJDBCProtocolU2Impl.<init>(UniJDBCProtocolU2Impl.java:116)
        at com.ibm.u2.jdbc.UniJDBCConnectionImpl.<init>(UniJDBCConnectionImpl.java:137)
        at com.ibm.u2.jdbc.UniJDBCDriver.connect(UniJDBCDriver.java:111)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:207)
        at testjdbc.Main.main(Main.java:36)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
        at asjava.uniclientlibs.UniTokens.<clinit>(UniTokens.java:109)
        ... 7 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Mi Código de prueba:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package testjdbc;
import java.sql.*;
import java.io.*;

 /**
 *
* @author norm
 */
public class Main {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {

    Connection con = null ;

    try{
        // generate URL

    String url = "jdbc:ibm-u2://my.uv.db:31438/DB-ACCOUNT;user=me;password=pass"; //testing, I remove user and password from here and use them below. Still FAILS!!! ARGGGG!!!
    String user = "me";
    String password = "pass";

    String driver = "com.ibm.u2.jdbc.UniJDBCDriver";
    //Load driver and connect to server
    Class.forName(driver);
    System.out.println("driver loaded");
    System.out.println("Connecting...");
    con = DriverManager.getConnection(url); //This is line 36
    // con = DriverManager.getConnection(url, user, password); // gives the same error
    //con = DriverManager.getConnection("jdbc:ibm-u2://my.uv.db:31438/D:/PathTo/DB;" ); //and yet the same error for this as well
    System.out.println("Connection String sent");
    System.out.println("Querying...");
    testQuery( con ) ;

    }
    catch ( SQLException e ) {
        System.out.println("Ex-Message :" + e.getMessage());
        System.out.println("Ex-Code    :" + e.getErrorCode()) ;
        System.out.println("Ex-SQLState:" + e.getSQLState());
        System.out.println("Ex-Next    :" + e.getNextException());
        e.printStackTrace() ;
        System.gc();
  } catch ( Exception e) {
        System.out.println("Exception caught:"+e) ;
        e.printStackTrace() ;
  }
}

public static void testQuery(Connection con)
    throws SQLException
{
    Statement stmt = con.createStatement();
    String sql = "select FIRST.NAME from EMPCEL";
            //"select @ID, CITY, STATE, ZIP, PHONE from CUSTOMER";

    // Execute the SELECT statement
    ResultSet rs = stmt.executeQuery(sql);

    // Get result of first five records
    System.out.println("\tlist selected columns for the first five records:");
    int i = 1;
    while (rs.next() && i < 6)
    {
        System.out.println("\nRecord "+ i +" :");
        System.out.println("\tFirst Name : \t" + rs.getString(1));
//            System.out.println("\tCITY :\t" + rs.getString(2));
//            System.out.println("\tSTATE :\t" + rs.getString(3));
//            System.out.println("\tZIP : \t" + rs.getString(4));
//            System.out.println("\tPHONE :\t" + rs.getString(5));
        i++;
        System.out.println("Finished.");
    }

    rs.close();
    stmt.close() ;
    System.out.println("\n\t*--- QUERY test is done successful ---*\n");
}

}
¿Fue útil?

Solución

Esto parece estar relacionado Netbeans. Ver también este tema en su foro. Parece que funciona en Eclipse (y posiblemente todos los otros entornos).

Esto es claramente un error en el controlador JDBC UniVerse. Es aparentemente estática dentro del inicializador depender de alguna condición ambiental específica, que es diferente en Netbeans. Si no fuera un error, habría arrojado una excepción mucho más autoexplicativo, no es una de esas excepciones de tiempo de ejecución tonta.

Me daría un informe sobre este error para IBM / universo.

Otros consejos

Si el código presentado es el que realmente causó la excepción, entonces supongo, se produce un error porque es url null a la hora de intentar conseguir la conexión.

Pero el error StackTrace muestra un error en la línea 36, ??que es la línea de comentario. Así que si mi suposición es incorrecta, por favor, edite su mensaje de pregunta y el presente código coincidente y error y marca la línea de código que produce la excepción.


Usted no está solo: mismo problema

he experimentado este problema también. UniTokens está asumiendo que hay una conversión de uno por uno de bytes a caracteres, pero no es cierto para todas las plataformas. Al pasar un argumento para la JVM evita este problema. Trate -Dfile.encoding = "windows-1252" o -Dfile.encoding = "US-ASCII"

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top