db2 jdbc connection

blade

Bekanntes Mitglied
Hallo, kann mir hier einer erklären wie man eine connection von java nach db2 macht?
hab das ganze thema schonmal hier reingeschrieben, damals hab ich aber nicht mehr weiter an dem thema geartbeitet.
hat vlt. einer ein gutes howto oder kann es mir erklären?
wie kann ich eine jdbc verbindung einrichten?
 
Hallo, hab jetzt diesen code zusammenbebaut:

package jdbcdb2;


import java.sql.*;
import java.sql.Connection;
import com.ibm.db2.jcc.*;


Java:
public class Main
        {
    public static void main(String[] args) throws Exception {

    
        */
        // JDBC-Treiber laden
try {

    /*
Class.forName("com.ibm.db2.jdbc.net.DB2Driver");
} catch (ClassNotFoundException exc) {
System.err.println("Could not load DB2Driver:" + exc.toString());
System.exit(1);
}
*/

      Class.forName("com.ibm.db2.jcc.DB2Driver");
        } catch(java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");
            System.err.println(e.getMessage());
        }

// Verbindung zur Datenbank herstellen

try {
String url = "jdbc:db2://localhost:50000/TESTDB";
Connection con = null;
con = DriverManager.getConnection(url, "db2user", "12345");


Statement stmt = con.createStatement();
String query = ("SELECT * FROM auto");
ResultSet rs = stmt.executeQuery(query);

while ( rs.next() )
        System.out.printf( rs.getString(1));
                           //rs.getString(2), rs.getString(3) );




rs.close();
stmt.close();
con.close();


} catch (SQLException exc) {
System.out.println("JDBC/SQL error: " + exc.toString());
return;



}
    }
}

bekomme aber diese Fehlermeldung:
run:
JDBC/SQL error: com.ibm.db2.jcc.am.io: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2USER.AUTO, DRIVER=3.57.82
BUILD SUCCESSFUL (total time: 2 seconds)

Kann mir einer das erklären? user ist angelegt, richtiges kennwort, richtige tabelle richtige rechte...
verstehe wer will..
 
Code:
SQL0204
Message Text: 	&1 in &2 type *&3 not found.
Cause Text: 	&1 in &2 type *&3 was not found. If this is an ALTER TABLE statement and the type is *N, a constraint or partition was not found. If this is not an ALTER TABLE statement and the type is *N, a function, procedure, or trigger was not found. If a function was not found, &1 is the service program that contains the function. The function will not be found unless the external name and usage name do not match exactly. Examine the job log for a message that gives more details on which function name is being searched for and the name that did not match.
Recovery Text: 	Change the name and try the request again. If the object is a node group, ensure that the DB2 Multisystem product is installed on your system and create a node group with the CRTNODGRP CL command. If an external function was not found, be sure that the case of the EXTERNAL NAME on the CREATE FUNCTION statement exactly matches the case of the name exported by the service program.
SQLCODE or SQLCODEs: 	+204, -204
SQLSTATE or SQLSTATEs: 	01532, 42704

http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/db2/rbafzmstcksql.htm

Keine Ahnung was das im detail heißt - db2 hab ich immer gemieden 😉
 
Hallo Blade,

bei DB2 muss man ziemlich aufpassen, da sind Schema und User oft identisch. Versuch mal bei dem Select das Schema davor zu schreiben. Also

SELECT * FROM TESTDB.auto

oder du nennst den Nutzer wie das Schema, ist aber nicht zu empfehlen, da bei jedem User ein Benutzer im Betriebssystem angelegt wird.

Grüße
jpee
 

Neue Themen


Zurück
Oben