Problem creating new databases and updating existing mdb file.
Can someone provide example code as to how to create a new database and create a table in it ? Ultimately I want to end up with an mdb file that contains four tables.
I can select tables out of an existing mdb fine but I am unable to create a new database and create tables in it. For example:
Class.forName("com.hxtt.sql.access.AccessDriver");
String url = "jdbc:Access:/c:/tmp/data";
Connection con = DriverManager.getConnection(url, new Properties());
Statement stmt = con.createStatement();
stmt.execute("create schema mydb");
stmt.execute("create table if not exists mydb.mytable (name varchar(80), address varchar(255))");
Fails with
[java] java.sql.SQLException: Failed to load database mydb! For more information, please use SQLException.getNextException().
[java] at com.hxtt.global.SQLState.SQLException(Unknown Source)
<...>
[java] at com.contentdiscovery.cds.apps.TestAccess.main(TestAccess.java:39)
[java] java.io.FileNotFoundException: C:\tmp\data\mydb.MDB (The system cannot find the file specified)
[java] java.sql.SQLException: java.io.FileNotFoundException: C:\tmp\data\mydb.MDB (The system cannot find the file specified)
Also, when I open an existing mdb database and perform updates on the table they do not take effect, even though the update was committed and the number of rows effected as indicated by the return value to executeUpdate() indicates that a row was updated. A subsequent select of the table shows that the update did not take effect.
|
> Can someone provide example code as to how to create a new database and create a table in it ? Ultimately I want to end up with an mdb file that contains four tables.
Our programmers are writing code for CREATE TABLE and CREATE DATABASE, but that function hasn't been provided now.
>when I open an existing mdb database and perform updates on the table they do not take effect
INSERT/UPDATE/DELETE should work normal. Just let us see your sql. Thanks.
|
The following code fragment doesn't work.
Class.forName("com.hxtt.sql.access.AccessDriver");
String url = "jdbc:Access:/c:/tmp/mydata.mdb";
Connection con = DriverManager.getConnection(url, new Properties());
ResultSet rs = con.createStatement().
executeQuery("select Title from export where id = 2");
while(rs.next()) {
String title = rs.getString(1);
System.out.println("Title = " + title);
}
int count = con.createStatement().
executeUpdate("update export set Title = 'New Title' where id = 2");
System.out.println("Updated " + count + " rows.");
rs = con.createStatement().
executeQuery("select Title from export where id = 2");
while(rs.next()) {
String title = rs.getString(1);
System.out.println("Title = " + title);
}
con.close();
This is the output:
Title = Rx_11Mbps_SNR20_Channel1_CarrierOffset0_ClockOffset40
Updated 1 rows.
Title = Rx_11Mbps_SNR20_Channel1_CarrierOffset0_ClockOffset40
|
Passed test with the below output:
Title = Rx_11Mbps_SNR20_Channel1_CarrierOffset0_ClockOffset40
Updated 1 rows.
Title = New Title
If possible, please email us your mydata.mdb or email a download url to webmaster@hxtt.com . Thanks.
|
Passed test with the below output:
Title = Rx_11Mbps_SNR20_Channel1_CarrierOffset0_ClockOffset40
Updated 1 rows.
Title = New Title
If possible, please email us your mydata.mdb or email a download url to webmaster@hxtt.com . Thanks.
|
A complementary explanation:
Since 2005-09-12, HXTT Access v1.0 supports REATE TABLE and CREATE INDEX.
HXTT Access v1.0.43 supports CREATE DATABASE.
HXTT Access v1.0.62 supports DROP TABLE.
|