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();
}
}
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).