怎么通过JAVA编程创建ACCESS数据库?
程序如下:
import java.sql.*;
public class DBManager
{
public static void main(String args[])
{
String serverName="127.0.0.1";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:xixi","hehe","123");
Statement s=conn.createStatement();
String sqlStatement = "create table bstore("+"id varchar2(10),name char(40),"+
"price number(6,2),author(40),"+"publisher char(40),note char(300),"+
"quantity)";
System.out.println(sqlStatement);
s.execute(sqlStatement);
for(int i=0;i<50;i++)
{
s.executeUpdate("insert into bstore values("+"'ISBN"+(1000+i)+"',"+
"'<java思想>(第"+(i+1)+"卷)'"+(30.00+i)+
",'Bily','TUP','a java handbook',1000)");
}
String id="ISBN10001";
String sql="update bstore set quantity="+30+"where id="+id+"";
s.executeUpdate(sql);
ResultSet rs=s.executeQuery("select*from bstore");
while(rs.next())
{
System.out.print(rs.getString(1).trim());
System.out.print(rs.getString(2).trim());
System.out.print("\t"+rs.getDouble(3));
System.out.print("\t"+rs.getString(4).trim());
System.out.print("\t"+rs.getString(5).trim());
System.out.print("\t"+rs.getInt(7));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
编译可以通过,但运行的结果是:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 字段定义语法错
误。
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6106)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6263)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2525)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:337)
at DBManager.main(DBManager.java:13)
Press any key to continue...
请把我找出原因?是不是在在JAVA中不能创建Access数据库?
ACCESS的创建问题