package com.ruoyi;
|
|
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.sql.Statement;
|
|
|
|
public class JDBCAccess {
|
|
public static void main(String[] args) {
|
|
// url表示需要连接的数据源的位置,此时使用的是JDBC-ODBC桥的连接方式,url是"jdbc:odbc:数据源名"
|
|
String url2= "jdbc:Access://192.168.141.104/jdbc:odbc:EventData";
|
String url = "jdbc:rmi://192.168.141.104/jdbc:odbc:EventData";
|
try {
|
|
Class.forName("com.hxtt.sql.access.AccessDriver");
|
|
Connection conn = DriverManager.getConnection(url);
|
|
Statement stat = conn.createStatement();
|
|
String sql = "select * from events";
|
|
ResultSet rs = stat.executeQuery(sql);
|
|
while(rs.next()){
|
|
System.out.println(rs.getString(2));
|
|
}
|
|
} catch (ClassNotFoundException | SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|