WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   problem mit mysql-connection über java (http://www.wcm.at/forum/showthread.php?t=95263)

RaistlinMajere 27.04.2003 14:18

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).

kju 27.04.2003 15:00

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");
          }


RaistlinMajere 27.04.2003 15:44

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...][:port]/[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.

kju 27.04.2003 16:13

das sollte helfen:
http://www.jsp-develop.de/knowledgebase/view/3401/

RaistlinMajere 27.04.2003 17:56

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?

RaistlinMajere 27.04.2003 23:05

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! :)


Alle Zeitangaben in WEZ +2. Es ist jetzt 02:06 Uhr.

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