Ich wollte eine Datenbankverbidung herstellen, allerdings bekomme ich immer eine recht eigenartige Fehlermeldung:
Ich verstehe nicht, woran das liegen könnte. Ich habe MySQL 5.6.26, ich habe darüber hinaus mysql-connector-java-5.0.8. Liegt das eventuell an einer mangelnden Kompatibilität?
Hier der Code:
java.sql.SQLException: No suitable driver found for jdbc:/opt/lampp/bin/mysql://localhost:3306/project2
Hier der Code:
Code:
package core; import java.sql.*; public class Main { final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; final String DB_URL = "jdbc:/opt/lampp/bin/mysql://localhost:3306/project2"; //Dies muesste ok sein. static final String USER = "root"; static final String PASS = "supergeheim"; public void start(){ Connection conn = null; Statement stmt = null; try{ Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(DB_URL,USER,PASS); /* stmt = conn.createStatement(); String sql; sql = "SELECT id, first, last, age FROM persons"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ int id = rs.getInt("id"); int age = rs.getInt("age"); String first = rs.getString("first"); String last = rs.getString("last"); System.out.print("ID: " + id); System.out.print(", Age: " + age); System.out.print(", First: " + first); System.out.println(", Last: " + last); } rs.close(); stmt.close(); conn.close(); }catch(SQLException se){ se.printStackTrace(); */ }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(stmt!=null) stmt.close(); }catch(SQLException se2){ }// nothing we can do try{ if(conn!=null) conn.close(); }catch(SQLException se){ se.printStackTrace(); } } } public static void main(String[] args){ Main m = new Main(); m.start(); } }
Comment