SQLException: No suitable driver bei DB2

Status
Nicht offen für weitere Antworten.
Hallo allerseits, bin mal wieder hier um ne dumme Frage zu stellen:

Dieser Code...

Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Datenbank
{
	public static void main(String[] args)
	{
      Connection cn = null;
      Statement  st = null;
      ResultSet  rs = null;

      try 
      {
		Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
		java.sql.Driver d = (java.sql.Driver)Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();
		System.out.println(d.acceptsURL("jdbc:db2:Test"));
      }
      catch (ClassNotFoundException e) 
      {
		e.printStackTrace();
	  } 
      catch (InstantiationException e) 
      {
		e.printStackTrace();
	} catch (IllegalAccessException e) 
	{
		e.printStackTrace();
	} catch (SQLException e) 
	{
		e.printStackTrace();
	}
      try 
      {
		cn = DriverManager.getConnection("jdbc:db2:Test","db2admin","test");
      } 
      catch (SQLException e) 
      {
		e.printStackTrace();
      }
	}
}

...liefert folgende Ausgabe


Code:
false
java.sql.SQLException: No suitable driver found for jdbc:db2:Test
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at Datenbank.main(Datenbank.java:37)

Wenn ich aber

Code:
System.out.println(d.acceptsURL("jdbc:db2://localhost:50000/Test"));

und

Code:
cn = DriverManager.getConnection("jdbc:db2://localhost:50000/Test","db2admin","test08");


verwende, funktioniert es.

Wenn ich das nun ohne den Umweg "localhost" machen will, wie muss ich das dann machen bzw. was ist an "jdbc:db2:Test" so falsch? Laut Tutorials müsste das doch auch funktionieren...
 

tfa

Top Contributor
Welches Tutorial? Nimm lieber die Dokumentation des DB2-Treibers.
Die jdbc-URL von DB2 muss eben den Hostnamen enthalten, sonst gibt's den Fehler.
 
Mein Tutorial:

http://beuter.dynalias.com/javainsel7/javainsel_22_005.htm#mj730ba4edc8f42232f7127d9e51c2c803

Unter Punkt 22.5.5 steht in der Tabelle

jdbc:derby:net://host:1527/
Das sieht für mich auch so aus als ob da noch eine IP-Adresse bzw. localhost hinein muss, aber bei DB2 steht

jdbc:db2://database

Mit

Code:
cn = DriverManager.getConnection("jdbc:db2://Test","db2admin","test");

hat's auch nicht funktioniert.

Und auf der IBM Seite http://publib.boulder.ibm.com/infocenter/db2luw/v8//index.jsp hab ich folgendes gefunden unter
Entwickeln->Datenbankanwendungen->Programmieren von Anwendungen->Java->JDBC->Herstellen einer Verbindung zu einer Datenquelle->Herstellen einer Verbindung zu einer Datenquelle

Syntax for a URL for the DB2 JDBC Type 2 Driver:

Read syntax diagramSkip visual syntax diagram>>-jdbc:db2:database-------------------------------------------><

Und ein Beispiel ist auch dabei:

Example: Setting the user ID and password in a java.util.Properties object:

Properties properties = new Properties(); // Create Properties object
properties.put("user", "db2adm"); // Set user ID for connection
properties.put("password", "db2adm"); // Set password for connection
String url = "jdbc:db2:toronto";
// Set URL for data source
Connection con = DriverManager.getConnection(url, properties);
// Create connection

Da steht ja auch
"String url = "jdbc:db2:toronto";
Demnach müsste es doch so auch gehen, wie ich ursprünglich vorhatte - ohne localhost usw. also, so in etwa:
Code:
cn = DriverManager.getConnection("jdbc:db2:Test","db2admin","test");

mfg
 

tfa

Top Contributor
Das Tutorial von IBM gilt nur für den Typ2-Treiber. Oben siehst du die Treiberklasse:
"COM.ibm.db2.jdbc.app.DB2Driver"

Du verwendest den Typ 3-Treiber (COM.ibm.db2.jdbc.net), da ist offensichtlich der Hostname Vorschrift. Versuch's mit Typ 2, obwohl der eigentlich veraltet ist. Oder nimm gleich Typ 4 (siehe anderer Thread) und gib den Hostnamen mit an, also localhost. Wo ist das Problem?

http://www.ibm.com/developerworks/data/library/techarticle/0307zikopoulos/0307zikopoulos.html
 
Ahja, wenn in
Code:
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
das net durch app ersetze, gehts mit
Code:
cn = DriverManager.getConnection("jdbc:db2:Test","db2admin","test08");

Ist ja auch irgendwie verständlich dass eine IP gefordert wird wenn ich irgendwas aus dem net-Unterpaket nehme...
das kommt eben davon wenn man sich aus verschiedenen Tutorials und Beispielen irgendwas zusammenbastelt.

Wieder was gelernt. Ich schau mir das mit dem Typ4 Treiber mal an, allerdings ist das DB2 welches ich habe auch schon ziemlich alt...

Vielen Dank, tfa!



P.S.: Ein Problem war das nicht wirklich, es hat ja mit localhost funktioniert. Aber ich wills halt dann schon ganz genau wissen wenn etwas nicht so tut wie ich denke ;)
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
V SQLite java.sql.SQLException: no such column: Datenbankprogrammierung 18
D MySQL SQLException time zone value is unrecognized Datenbankprogrammierung 2
M Oracle SQLException: Verbindung getrennt Datenbankprogrammierung 2
S MySQL SQLException Parameter index out of range (1 > number of parameters, which is 0). Datenbankprogrammierung 10
B Probleme mit java.sql.SQLException: ResultSet closed Datenbankprogrammierung 21
nrg Oracle java.sql.SQLException Ungültiger Vorgang bei schreibgeschützter Ergebnismenge Datenbankprogrammierung 0
N SQL-Statement SQLException: the '|' object Datenbankprogrammierung 3
N SQL-Statement SQLException: '' is not a valid name. Datenbankprogrammierung 7
Y java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state Datenbankprogrammierung 2
H Derby/JavaDB SQLException wenn die Datenbank in eine Jar gepackt wurde. Datenbankprogrammierung 6
I java.sql.SQLException: No data found Datenbankprogrammierung 3
T java.sql.SQLException: unexpected end of statement Datenbankprogrammierung 2
H java.sql.SQLException: Access denied for user 'root'@'localhost' (using password : YES) Datenbankprogrammierung 1
D getConnection mit SQLException Datenbankprogrammierung 7
F SQLException fangen beim verbinden mit Hibernate Datenbankprogrammierung 17
D java.sql.SQLException Datenbankprogrammierung 3
J Einstellungen für die Ausnahme SQLException Datenbankprogrammierung 7
M java.sql.SQLException: Unable to open file Datenbankprogrammierung 2
M java.sql.SQLException: out of memory Datenbankprogrammierung 18
zilti java.sql.SQLException: Before start of result set Datenbankprogrammierung 2
C FM: java.sql.SQLException: Geschlossene Ergebnismenge: next Datenbankprogrammierung 7
A Problem: java.sql.SQLException Datenbankprogrammierung 5
I hilfe! java.sql.SQLException Datenbankprogrammierung 7
M java.sql.SQLException: No data found Datenbankprogrammierung 9
K MsAccess immer beim zweiten Update java.sql.SQLException Datenbankprogrammierung 28
C SQLException wenn String auf VARCHAR geschrieben wird Datenbankprogrammierung 10
G SQLException: Lässt sich der Fehler feststellen? Datenbankprogrammierung 10
R MySQL denies access to data source - java.sql.SQLException Datenbankprogrammierung 14
L SQLException --> Übersetzung nötig! Datenbankprogrammierung 2
G SQLException: No operations allowed after connection closed Datenbankprogrammierung 2
K java.sql.SQLException: Before start of result set Datenbankprogrammierung 2
B SQLite + jdbc + IntelliJ-Consumer = "No suitable driver found..." Datenbankprogrammierung 15
D MySQL No Suitable Drivers found Datenbankprogrammierung 4
J RESTServie + JDBC + No suitable driver found for jdbc Datenbankprogrammierung 4
B No suitable driver found for jdbc:oracle:thin:@$HOST:$PORT:$SID Datenbankprogrammierung 7
AMStyles No suitable driver found for Datenbankprogrammierung 4
A No suitable driver found for jdbc:microsoft:sqlserver... Datenbankprogrammierung 9
N Derby/JavaDB No suitable driver found Datenbankprogrammierung 14
StYxXx Microsoft-SQL: No suitable driver found Datenbankprogrammierung 11
Y Java und MySql... "No suitable Driver..." Datenbankprogrammierung 16
G No suitable driver Datenbankprogrammierung 8
G No suitable driver Datenbankprogrammierung 16
G Das tolle "No suitable driver found" Datenbankprogrammierung 4
S no suitable driver Datenbankprogrammierung 2
G MySQL: Login-Problem: No suitable Driver Datenbankprogrammierung 13
Maxim6394 EclipseLink + SQLite | Unable to acquire a connection from driver [null] Datenbankprogrammierung 6
ralfb1105 Oracle Zwei ojdbc Driver in einer Applikation? Datenbankprogrammierung 13
thet1983 Derby/JavaDB Embedded Driver Datenbankprogrammierung 7
thet1983 MySQL ODBC Driver zuweisen unter Mac OX Mav Datenbankprogrammierung 2
T JAR keine H2 driver? Datenbankprogrammierung 3
Q Oracle Linux: ClassNotFoundException: oracle.jdbc.driver.OracleDriver Datenbankprogrammierung 6
K JDBC Driver not found Datenbankprogrammierung 10
S MSSQL JDBC "Driver class not found" Datenbankprogrammierung 9
S Access 2007 zugreifen- ODBC Driver Manger Datenbankprogrammierung 3
K org.gjt.mm.mysql.driver wird nicht gefunden Datenbankprogrammierung 11
F MySQL - Connection JDBC-Driver Problem Datenbankprogrammierung 4
S java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Datenbankprogrammierung 10
F DBConnect schläg fehl: not suitble Driver ?!? Datenbankprogrammierung 4
N MS-acces JDBC driver Datenbankprogrammierung 3
D Jdbc: Unable to load Driver! Datenbankprogrammierung 11
H Fehler mit ". Microsoft Access Driver" Datenbankprogrammierung 12
G MySQL Driver Bug? Datenbankprogrammierung 6
H Konnte den Treiber com.mysql.jdbc.Driver nicht laden. Datenbankprogrammierung 19
L Wo bekomme ich: "org.gjt.mm.mysql.Driver"? Datenbankprogrammierung 1
zilti java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Datenbankprogrammierung 3
D java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Datenbankprogrammierung 5
B Oracle Driver Probleme Datenbankprogrammierung 2
E Problem beim laden des JDBC Driver bzw der Database Datenbankprogrammierung 8
R NetBeans und com.mysql.jdbc.Driver Datenbankprogrammierung 2
N [Microsoft][ODBC Microsoft Access Driver]COUNT field incorre Datenbankprogrammierung 13
K Mysql Driver Datenbankprogrammierung 2

Ähnliche Java Themen

Neue Themen


Oben