So I am trying to make a connection with JDBC using XAMPP, but it doesn't work, What am I doing wrong here?
public static void main(String args[]) {
try {
Connection myConn = DriverManager.getConnection(
"http://localhost/phpmyadmin/sql.php?db=a3_eindopdracht_2&table=namen&pos=0", "", "");
Statement myStm = myConn.createStatement();
ResultSet myRs = myStm.executeQuery("SELECT * FROM namen");
while (myRs.next()) {
System.out.println(myRs.getString("voornaam") + " " + myRs.getString("achternaam"));
}
} catch (Exception exc) {
exc.printStackTrace();
}
Firstly, you don't find Driver. You have to load them, by calling the Drive class like that :
Then, you are trying to connect to your databse with HTTP protocol. But, DB have they own (with port 3306 by default), so you have to use address like that:
Finally: don't forget to add username and password on last 2 fields of getConnection method