无法连接到我的 Derby 数据库
我使用 Java DB 创建了一个名为“Test”的新数据库,并尝试使用 java DB Embedded 驱动程序创建连接,但是当我在数据库名称中输入 Test 并添加用户名并通过并按“确定”时,出现错误:
“无法添加连接。无法使用 org.apache.derby.jdbc.EmbeddedDriver 建立与 jdbc.derby.Test 的连接(未找到数据库“Test”)”
为什么会收到此消息?
然后,当我编写代码时,
String conStr = "jdbc:derby:Test";
String driver2 = "org.apache.derby.jdbc.EmbeddedDriver";
try {
Class.forName(driver2);
System.out.println("driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
Properties props = new Properties();
props.put("user", "sahar");
props.put("password", "123456");
//Connection conn = DriverManager.getConnection(conStr);
Connection conn = DriverManager.getConnection(conStr,props);
System.out.println("connect ");
} catch (SQLException e) {
e.printStackTrace();
}
它会抛出异常“未找到数据库‘测试’”
I created a new database using Java DB named "Test", and I tried to create a connection using java DB Embedded driver, but when I enter Test in database name and add user name and pass and press OK, an error appears:
"Unable to add connection. cannot establish a connection to jdbc.derby.Test using org.apache.derby.jdbc.EmbeddedDriver (database 'Test' not found)"
Why do I get this message?
then, when I wrote my code
String conStr = "jdbc:derby:Test";
String driver2 = "org.apache.derby.jdbc.EmbeddedDriver";
try {
Class.forName(driver2);
System.out.println("driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
Properties props = new Properties();
props.put("user", "sahar");
props.put("password", "123456");
//Connection conn = DriverManager.getConnection(conStr);
Connection conn = DriverManager.getConnection(conStr,props);
System.out.println("connect ");
} catch (SQLException e) {
e.printStackTrace();
}
it throws an exception "Database 'Test' not found"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您确实创建了本地数据库,请尝试指向绝对文件名而不是相对文件名。
更好的方法可能是通过 Derby 网络服务器访问数据库
If indeed you have created a local database, try pointing to the absolute file-name instead of the relative one.
Better way might be to access a database via a Derby network server
如果没有看到代码,很难猜测,但也许您的连接字符串上需要
create=true
。(我从使用嵌入式数据库的应用程序中提取了此副本并粘贴。)
Without seeing code it's hard to guess, but perhaps you need
create=true
on your connection string.(I pulled this copy and paste out of an app I have that uses an embedded database.)