WCM - Das österreichische Computer Magazin Forenübersicht
 

Zurück   WCM Forum > Rat & Tat > Programmierung

Programmierung Rat & Tat für Programmierer

Microsoft KARRIERECAMPUS

Antwort
 
Themen-Optionen Ansicht
Alt 27.04.2003, 14:18   #1
RaistlinMajere
Inventar
 
Registriert seit: 06.04.2001
Alter: 44
Beiträge: 2.343


Standard problem mit mysql-connection über java

Code:
  try {
    String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
    Properties systemProperties = System.getProperties();

    systemProperties.put("jdbc.drivers", driverName);
    System.setProperties(systemProperties);

    Connection DBcontact = DriverManager.getConnection("jdbc:odbc:testDB", username, passwort);
    ausgabe = "verbindung erfolgreich";
  }
  catch(Exception e) {
    ausgabe = e + "";
  }
ich bekomme da die exception, daß angeblich die datenquelle nicht gefunden wurde und kein standardtreiber angegeben wurde. den code habe ich an sich aus einem buch, ich check echt nicht ab, was da falsch sein sollte (username, passwort usw. hab ich natürlich schon überprüft).
____________________________________
"Life is like a box of rockets," said the Marine. "You never know what you´re gonna ret."
Then he pulled the trigger of his BFG9000.
RaistlinMajere ist offline   Mit Zitat antworten
Alt 27.04.2003, 15:00   #2
kju
Senior Member
 
Registriert seit: 28.05.2002
Alter: 47
Beiträge: 141


kju eine Nachricht über ICQ schicken
Standard

versuchs ma so:
nat. mit dem richtigen treiber, http://www.mysql.com/downloads/api-jdbc-stable.html


Code:
 String user = "Admin";
 String password = "";
 String url = "jdbc:mysql://localhost/test";
 String driver = "com.mysql.jdbc.Driver";
 Connection con;
 try{
      //Verbindung zur Datenbank herstellen
      Class.forName(driver);
      con = DriverManager.getConnection(url, user, password);
      
      System.out.println("db-eingang");
      ....
      //Fehler bei Datenbankanbindung abfangen
          }catch(ClassNotFoundException cnfe){
                System.err.println(cnfe+"bei Initialisierung");
          }catch(SQLException sqle){
           System.err.println(sqle+"Fehler bei der Datenbankanbindung");
          }
____________________________________
There are two rules for ultimate success in life.
1. Never tell everything you know.
kju ist offline   Mit Zitat antworten
Alt 27.04.2003, 15:44   #3
RaistlinMajere
Inventar
 
Registriert seit: 06.04.2001
Alter: 44
Beiträge: 2.343


Standard

ok, der richtige treiber dürfte das sein, danke.
nur hab ich jetzt noch das problem, daß ich nicht weiß, wie ich den richtigen treiber einbauen soll.
das ganze soll nämlich eine JSP sein, normalerweise würde ich diesen ja einfach zum klassenpfad hinzufügen, aber wie funzt das hier?

aus der readme werd ich nicht ganz schlau.

Zitat:
Put mysql-connector-java-3.0.7-stable-bin.jar in your classpath, either by adding the
FULL path to it to your CLASSPATH enviornment variable, or putting it
in $JAVA_HOME/jre/lib/ext.

If you are using a servlet engine or application server, you will have
to read your vendor's documentation for more information on how to
configure third-party class libraries, as most application servers
ignore the CLASSPATH environment variable. If you are developing
servlets and/or JSPs, and your application server is J2EE-compliant,
you should put the driver's .jar file in the WEB-INF/lib subdirectory
of your webapp, as this is the standard location for third party
class libraries in J2EE web applications. You can also use the
MysqlDataSource, MysqlConnectionPoolDataSource or MysqlXADataSource
classes in the com.mysql.jdbc.jdbc2.optional package, if your J2EE
application server supports/requires them. MysqlDataSource supports the
following parameters (through standard "set" mutators):

user
password
serverName (see the next section about fail-over hosts)
databaseName
port

If you are going to use the driver with the JDBC DriverManager, you would use
"com.mysql.jdbc.Driver" as the class that implements java.sql.Driver.

You might use this name in a Class.forName() call to load the driver:

Class.forName("com.mysql.jdbc.Driver").newInstance ();

To connect to the database, you need to use a JDBC url with the following
format ([xxx] denotes optional url components):

jdbc:mysql://[hostname][,failoverhost...][ort]/[dbname][?param1=value1][&param2=value2].....
das hinzufügen ins $JAVA_HOME/jre/lib/ext hab ich schon probiert, bringt aber leider nix. irgendwie muß ich ja den treiber wohl auch im quelltext einbinden.
____________________________________
"Life is like a box of rockets," said the Marine. "You never know what you´re gonna ret."
Then he pulled the trigger of his BFG9000.
RaistlinMajere ist offline   Mit Zitat antworten
Alt 27.04.2003, 16:13   #4
kju
Senior Member
 
Registriert seit: 28.05.2002
Alter: 47
Beiträge: 141


kju eine Nachricht über ICQ schicken
Standard

das sollte helfen:
http://www.jsp-develop.de/knowledgebase/view/3401/
____________________________________
There are two rules for ultimate success in life.
1. Never tell everything you know.
kju ist offline   Mit Zitat antworten
Alt 27.04.2003, 17:56   #5
RaistlinMajere
Inventar
 
Registriert seit: 06.04.2001
Alter: 44
Beiträge: 2.343


Standard

stimmt, ist ziemlich nützlich, der link, nur etwas checke ich noch nicht ganz ab:

Zitat:
Danach den Pfad zum Treiber im CLASSPATH ergänzen, z.B. so:

"f:\tomcat\common\lib\mm.mysql-2.0.14-bin.jar";
wie mache ich das genau?
____________________________________
"Life is like a box of rockets," said the Marine. "You never know what you´re gonna ret."
Then he pulled the trigger of his BFG9000.
RaistlinMajere ist offline   Mit Zitat antworten
Alt 27.04.2003, 23:05   #6
RaistlinMajere
Inventar
 
Registriert seit: 06.04.2001
Alter: 44
Beiträge: 2.343


Standard

funzt schon alles, nach befolgen der anleitung des links hat alles hingehauen. interessanterweise war aber trotzdem ein setzen eines klassenpfades nicht notwendig, es geht auch ohne.

danke vielmals!
____________________________________
"Life is like a box of rockets," said the Marine. "You never know what you´re gonna ret."
Then he pulled the trigger of his BFG9000.
RaistlinMajere ist offline   Mit Zitat antworten
Antwort


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 10:20 Uhr.


Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Forum SEO by Zoints
© 2009 FSL Verlag