ich bin neu in java. Ich versuche, MySQL DB in Javajava mysql db verbindung
Ich habe dieses
mysql.java file:
package program;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class mysql {
private static final String DATABASE_DRIVER = "com.mysql.jdbc.Driver";
private static final String DATABASE_URL = "jdbc:mysql://mysql.cba.pl:3306/dbname";
private static final String USERNAME = "login";
private static final String PASSWORD = "pass";
private static final String MAX_POOL = "250";
private Connection connection;
private Properties properties;
private Properties getProperties() {
if (properties == null) {
properties = new Properties();
properties.setProperty("user", USERNAME);
properties.setProperty("password", PASSWORD);
properties.setProperty("MaxPooledStatements", MAX_POOL);
}
return properties;
}
public Connection connect() {
if (connection == null) {
try {
Class.forName(DATABASE_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL, getProperties());
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
return connection;
}
public void disconnect() {
if (connection != null) {
try {
connection.close();
connection = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
Haupt-Java-Datei:
package program;
public class main {
public static void main(String[] args){
mysql db = new mysql();
db.connect();
}
}
und ich bekomme folgende Fehler
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at komunikator.mysql.connect(mysql.java:31)
at komunikator.main.main(main.java:7)
Ich heruntergeladen ojdbc6-11.2.0.2.0.jar und in meinem Projektordner, danach ich Bibliothek aus JAR-Datei hinzufügen. Was mache ich falsch? ich in Java wirklich neu bin, so kann ich jemand hoffe mich auch :)
ich Eclipse-Standard/SDK
Version helfen kann, bin mit: Kepler Veröffentlichung Build-ID: 20130614-0229
Duplikat von http://StackOverflow.com/Questions/1585811/ClassnotFoundexception-Com-Mysql-Jdbc-Triver - Sie könnten eine Lösung aus den Antworten dort finden! –
Mögliches Duplikat von [ClassNotFoundException com.mysql.jdbc.Driver] (http://stackoverflow.com/questions/1585811/classnotfundexception-com-mysql-jdbc-driver) – Antimony