I am trying to compile this small piece of code to help me connect to my db and get some information to check it. I am using Netbeans on a Windows 7 x64 computer. This is the code:
package passwordprotector; import java.sql.*; public class PasswordProtector { public static void main(String[] args) { String host = "jdbc:derby://localhost:1527/PasswordProtector DB"; String dbUsername = "john"; String dbPassword = "arsenal"; try{ Connection con = DriverManager.getConnection(host, dbUsername, dbPassword); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM APP.PERSON"); while (rs.next()) { String uName = rs.getString("uname"); String uPass = rs.getString("upass"); System.out.println("Username: " + uName + "/n" + "Password: " + uPass); } }catch(SQLException e){ System.err.println(e); } } }
When I compile and run, I get this error:
java.sql.SQLException: No suitable driver found for jdbc:derby:
When I right-click on my db and select properties, I can see its location, for example:
Database URL: jdbc:derby:
I checked with others who posted about it, and it looks like they had the wrong URL, but I don't see another URL that I can use separately from the published one.
I tried with and without end "DB" for the String host, not working.
I also read from here and still could not understand why URl is incorrect:
source share