日期:2014-05-20  浏览次数:20754 次

关于java数据库Access
我在java在连接数据库2010,代码如下:
package stock;
import java.sql.*;  
public class ConnectAccess {  
    
    public static void mbshow(ResultSet r)
    {
        try{
            r.last();
            System.out.println("数据库表共有"+r.getRow()+"条记录");
            r.beforeFirst();
            while(r.next())
            {
                System.out.println("第"+r.getRow()+"行记录");
                System.out.println("\t股票代码:"+r.getString("股票代码"));
                System.out.println("\t股票名称:"+r.getString("股票名称"));
                System.out.println("\t股票价格:"+r.getString("股票价格"));
                System.out.println("\t股票价格上限:"+r.getString("股票价格上限"));
                System.out.println("\t股票价格下限:"+r.getString("股票价格下限"));
            }
        }catch(Exception e)
        {
            System.err.println("异常2:"+e.getMessage());
        }
       
    }
    
    public static void main(String[]args)
    {
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection c = DriverManager.getConnection("jdbc:odbc:Database","","");
            Statement s = c.createStatement();
            ResultSet r=s.executeQuery("select * from Stock");
            mbshow(r);
        }catch(Exception e)
        {
             e.printStackTrace();
        }
    }


结果出现错误,如下:
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6985)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at stock.ConnectAccess.main(ConnectAccess.java:31)