好的,所以我决定遵循 Youtube 上关于数据库的教程,并在 PhpMyAdmin 上创建了一个数据库,然后将备份文件SQL
导出(我认为是一个表,而不是整个数据库)到我的桌面。我想使用 JDBC 连接到它,并使用下面的代码进行了尝试。(请注意,我确保驱动程序已正确安装出于调试目的,请假设我的桌面上仅存在该文件,我有驱动程序,以下代码,仅此而已。另外,我不确定如何将文件放在.SQL
(customers.sql)
Class.forName("com.mysql.jdbc.Driver");
sql
localhost
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/customers","root", "");
这段代码产生了一个异常:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'customers'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:395)
at com.mysql.jdbc.Util.getInstance(Util.java:370)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1038)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2467)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2500)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2285)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:818)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:395)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at com.gmail.PhysicistSarah.TestProject.Database.DatabaseDriver.<init>(DatabaseDriver.java:32)
at com.gmail.PhysicistSarah.TestProject.Core.Main.databaseTrial(Main.java:99)
at com.gmail.PhysicistSarah.TestProject.Core.Main.main(Main.java:49)