顯示在畫面上
import java.io.*; import java.sql.*; import jxl.*; public class AccseeODBCTest { public static void main(String[] argv){ String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; ResultSet re; try { Class.forName(driver); Connection cnDB = DriverManager.getConnection("jdbc:odbc:myAccess"); Statement stmt = cnDB.createStatement(); re = stmt.executeQuery("SELECT COUNT(*) AS allTable FROM StudentTable"); if(re.next()){ if(re.getInt("allTable")==0)System.out.println("目前尚無資料"); } re = stmt.executeQuery("SELECT * FROM StudentTable"); while(re.next()){ System.out.println( "客戶編號: " +re.getObject("客戶編號")+ "\n" + "客戶姓名: " +re.getObject("客戶姓名")+ "\n" + "---------------------------------------------\n" ); } stmt.close(); cnDB.close(); } catch(ClassNotFoundException e) { System.out.println("找不到驅動程式類別"); } catch(SQLException e) { System.out.println("找不到資料庫路徑"); e.printStackTrace(); } }// end of main }// end of class
沒有留言:
張貼留言