MS Access 2007 を使用してデータを挿入しようとすると、例外が発生し、[] 中かっこを使用して試しましたが、機能しません。DBF ファイルは正常に作成されますが、正確な出力は生成されません。
import java.sql.*;
public class Test
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = "mdbTEST";
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection con = DriverManager.getConnection(dbURL, "","");
// creating a java.sql.Statement so I can run queries
Statement s = con.createStatement();
s.execute("create table TESTME ( olumn_name integer )");
// creating a table
// inserting some data into the table
s.execute("insert into TESTME values(3)");
// selecting the data from the table
s.execute("[select column_name from TESTME]");
//getting any ResultSet that came from our query
ResultSet rs = s.getResultSet();
if (rs != null)
// if rs == null, then there is no ResultSet to view
while ( rs.next() )
{
/* the next line will get the first column in our current row's ResultSet
as a String ( getString( columnNumber) ) and output it to the screen */
System.out.println("[Data from column_name:]" + rs.getString(1) );
}
s.execute("drop table TESTME");
s.close();
con.close();
}
catch (Exception err)
{
System.out.println("ERROR: " + err);
}
}
}