Java和Firebird Embedded如何创建db?
现在我得到 java.sql.SQLException: No合适的驱动程序找到 jdbc:firebirdsql:embedded:f/test.fdb
我在我的项目中包含了 jaybird jars。请帮帮我
包实用程序;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.firebirdsql.gds.impl.GDSType;
import org.firebirdsql.management.FBManager;
public class FireBirdCreator {
public FireBirdCreator() {
FBManager manager = new FBManager(GDSType.getType("EMBEDDED"));
try {
manager.start();
manager.createDatabase("f:/test.fdb", "sysdba", "masterkey");
manager.stop();
Connection bd = DriverManager.getConnection("jdbc:firebirdsql:embedded:f/test.fdb");
Statement st = bd.createStatement();
st.execute("create table if not exists 'TABLE1' ('name1' int, 'name2' text, 'name3' text);");
st.execute("insert into 'TABLE1' ('name1', 'name2', 'name3') values (1, 'name1', 'name2'); ");
st.execute("insert into 'TABLE1' ('name1', 'name2', 'name3') values (2, 'name3', 'name4'); ");
st.execute("insert into 'TABLE1' ('name1', 'name2', 'name3') values (3, 'name5', 'name6');");
ResultSet rs = st.executeQuery("select * from TABLE1");
while (rs.next())
{
System.out.print (rs.getString(1)+" ");
System.out.print (rs.getString(2)+" ");
System.out.println(rs.getString(3));
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String args[]) {
FireBirdCreator fbc = new FireBirdCreator();
}
}
now i get java.sql.SQLException: No suitable driver found for jdbc:firebirdsql:embedded:f/test.fdb
i included jaybird jars with my project. please help me out
package util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.firebirdsql.gds.impl.GDSType;
import org.firebirdsql.management.FBManager;
public class FireBirdCreator {
public FireBirdCreator() {
FBManager manager = new FBManager(GDSType.getType("EMBEDDED"));
try {
manager.start();
manager.createDatabase("f:/test.fdb", "sysdba", "masterkey");
manager.stop();
Connection bd = DriverManager.getConnection("jdbc:firebirdsql:embedded:f/test.fdb");
Statement st = bd.createStatement();
st.execute("create table if not exists 'TABLE1' ('name1' int, 'name2' text, 'name3' text);");
st.execute("insert into 'TABLE1' ('name1', 'name2', 'name3') values (1, 'name1', 'name2'); ");
st.execute("insert into 'TABLE1' ('name1', 'name2', 'name3') values (2, 'name3', 'name4'); ");
st.execute("insert into 'TABLE1' ('name1', 'name2', 'name3') values (3, 'name5', 'name6');");
ResultSet rs = st.executeQuery("select * from TABLE1");
while (rs.next())
{
System.out.print (rs.getString(1)+" ");
System.out.print (rs.getString(2)+" ");
System.out.println(rs.getString(3));
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String args[]) {
FireBirdCreator fbc = new FireBirdCreator();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息表明该文件不存在。它显示“null”而不是实际文件名的事实可能是嵌入版本和 Jaybird 版本之间不匹配。
要创建数据库,您需要使用以下代码(并以正确的方式处理它抛出的异常):
另请注意,您用于创建表的 DDL 不是有效的 Firebird SQL。您将需要使用 RECREATE TABLE 并且 Firebird 没有名为
text
的类型。全面披露:我是 Jaybird(Firebird JDBC 驱动程序)的开发人员之一。
The error message indicates that the file does not exist. The fact that it shows 'null' instead of the actual filename might be a mismatch between embedded version and Jaybird version.
To create a database you need to use the following code (and handle the exceptions it throws in a correct manner):
Also be aware that the DDL you are using to create the table is not valid Firebird SQL. You will need to use RECREATE TABLE and Firebird does not have a type called
text
.Full disclosure: I am one of the developers of Jaybird (the Firebird JDBC driver).