我正在使用 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);
}
}
}