mysql未知数据库_jdbc中的未知数据库

本文介绍了一位JDBC初学者在尝试连接本地MySQL数据库kholofelodb时遇到的MySQLSyntaxErrorException。作者分享了错误堆栈信息,并寻求解决如何正确设置连接URL、驱动和表操作的方法。
摘要由CSDN通过智能技术生成

我正在使用JDBC和它的新功能。但我不断收到此运行时异常:

connecting to psysical database...

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'kholofelodb'

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:411)

at com.mysql.jdbc.Util.getInstance(Util.java:386)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)

at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113)

at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308)

at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)

at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:792)

at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)

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:411)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)

at java.sql.DriverManager.getConnection(DriverManager.java:579)

at java.sql.DriverManager.getConnection(DriverManager.java:221)

at com.psybergate.database.SimbleCode.main(SimbleCode.java:22)

这是给定的代码

try {

String connectionURL = "jdbc:mysql://localhost:3306/kholofelodb";

Class.forName("com.mysql.jdbc.Driver");

System.out.println("connecting to psysical database...");

Connection conn = DriverManager.getConnection(connectionURL, USER,

PASS);

Statement statement = conn.createStatement();

System.out.println("Connection has been made");

Scanner keyBoardScanner = new Scanner(System.in);

System.out.println("Enter table name:");

String tableName = keyBoardScanner.nextLine();

System.out.println("Creating table...");

statement.executeQuery("create table " + tableName

+ " (name , age ,salary)");

System.out.println("Table successfully created");

System.out.println("Inserting data into the table ...");

statement.executeUpdate("insert into " + tableName

+ "values (kholofelo , 21 , 9969696)");

}

如何使此代码起作用?我只是JDBC的初学者。

对于上面的代码;PASS =“ passowrd”,USER =“ root”

我在通过此站点修复的端口上遇到了问题

非常感谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值