java操作access,无需设置数据源
程序员文章站
2024-01-22 13:23:52
...
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class T { public static void main(String args[]) throws SQLException { Connection conn = null; try { String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=e:/1.mdb;"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Properties prop = new Properties(); prop.put("charSet", "gb2312"); // prop.put("user", ""); // prop.put("password", ""); conn=DriverManager.getConnection(strurl,prop) ; Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery("SELECT 课程名称 FROM Jpkc"); int i = 0; while (rs.next()) { i++; System.out.println(i+"\t"+rs.getString(1)); if(i>1003){ break; } } }catch(Exception e) { e.printStackTrace(); } conn.close(); } }