标题:ACCESS的创建问题
只看楼主
都市猎人
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-3-26
 问题点数:0 回复次数:1 
ACCESS的创建问题

怎么通过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 
2006-04-05 11:03
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
得分:0 
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(62),author char(40),"+"publisher char(40),note char(300),"+
"quantity number(10))";
System.out.println(sqlStatement);
s.execute(sqlStatement);

for(int i=0;i<50;i++)
{
String qu="insert into bstore values("+"'ISBN"+(1000+i)+"',"+
"'<java思想>(第"+(i+1)+"卷)',"+(30.00+i)+
",'Bily','TUP','a java handbook',1000)";
System.out.println("=====================================================");
System.out.println(qu);
s.executeUpdate(qu);
}

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();
}
}
}
还有别的地方,你用了全角的逗号,所以会出异常,我都改回来了,你可以运行一下

可惜不是你,陪我到最后
2006-04-05 11:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-55209-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.896146 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved