So, I have a problem connecting to MySQL with Java. Here is my code:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBAccess { private String Host; private String User; private String Password; public DBAccess() throws ClassNotFoundException, SQLException{ Class.forName("com.mysql.jdbc.Driver"); Password = "password"; Host = "jdbc:mysql://localhost/worlddb"; User = "root"; @SuppressWarnings("unused") Connection connect = DriverManager.getConnection(Host,User,Password); System.out.println("Connected!"); } public void RetreiveData(){ } public void ChangeData(){ } }
The error I get is the exception in the "main" thread
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'worlddb'
http://postimg.org/image/593stjvjx/ in mySQL workbench my connection name is "worlddb", hostname is Liquidus (which is the local host)
- socket is MySQL
- Port: 3306
Why is this?
java mysql jdbc
Chris phillips
source share