无法使用Ms Access连接java

时间:2014-10-21 11:58:05

标签: java

import java.io.*;
import java.sql.*;


public class MyClass {

    public static void main(String[] args)throws IOException {
        try { 
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection conn = DriverManager.getConnection("jdbc: odbc:STUD1");
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("SELECT* FROM STUD1");

            while(rs.next()) {
                System.out.print("ID" + rs.getString(1));
                System.out.print("Name" + rs.getString(2));
                System.out.print("Address" + rs.getString(3));      
            } 
        }catch (Exception ex){
            System.out.print("Not Connected");
        }
    }
}

此代码可以无错误地编译和运行,但它无法在.accdb中显示表内的内容,只能在cmd中打印出Not Connected。 如果编码不正确,请帮我找到方法。谢谢你

0 个答案:

没有答案