私はjavaで新しいです。java mysql db connection
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();
}
}
}
}
メインjavaファイル:
package program;
public class main {
public static void main(String[] args){
mysql db = new mysql();
db.connect();
}
}
私は私がこの
mysql.javaファイルを持っている
JavaでMySQLのDBに接続しようとしています
エラーが発生しました
ojdbc6-11.2.0.2.0.jarをダウンロードしてプロジェクトフォルダに入れた後、jarファイルからライブラリを追加します。 私は間違っていますか? 私は誰かが同様に私を助けることができると思いますので、私はJavaで本当に新しいです:)
私は、Eclipse標準/ SDKに
バージョン使用しています:ケプラーリリース ビルドID:20130614から0229
重複したhttp://stackoverflow.com/questions/1585811/classnotfoundexception-com-mysql-jdbc-driver - そこから解決策を見つけることができます。 –
[ClassNotFoundException com.mysql.jdbc.Driver]の重複している可能性があります(http://stackoverflow.com/questions/1585811/classnotfoundexception-com-mysql-jdbc-driver) – Antimony