Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySqlConnection {
- private String user;
- private String pwd;
- private String url;
- public MySqlConnection() {
- Properties p = new Properties();
- try {
- p.load(this.getClass().getClassLoader()
- .getResourceAsStream("database_infos.properties"));
- this.user = p.getProperty("USER");
- this.pwd = p.getProperty("PASSWORD");
- this.url = p.getProperty("URL");
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- public static void main(String[] args) {
- MySqlConnection mysqlConn = new MySqlConnection();
- Connection conn = null;
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- System.out.println("Driver load");
- conn = DriverManager.getConnection(mysqlConn.url, mysqlConn.user, mysqlConn.pwd);
- } catch (ClassNotFoundException | SQLException e) {
- e.printStackTrace();
- } catch (InstantiationException ex) {
- Logger.getLogger(MySqlConnection.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- Logger.getLogger(MySqlConnection.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- Driver load
- java.sql.SQLException: No suitable driver found for "jdbc:mysql://localhost:3306/BookManager"
- at java.sql.DriverManager.getConnection(DriverManager.java:689)
- at java.sql.DriverManager.getConnection(DriverManager.java:247)
- at mysqlconnection.MySqlConnection.main(MySqlConnection.java:53)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement