如何编写一个连接Access数据库的JSP动态网页 20
展开全部
public static void main(String args[]) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// ����Microsoft SQL server2000��2005��2008��ODBC
// String url = "jdbc:odbc:sql08";
// Connection connection =
// DriverManager.getConnection(url,"sa","qiaole");
// ����Microsoft Access2003��ODBC
// String url = "jdbc:odbc:accdb";
// String url =
// "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F:/Desktop/�ĵ�/word/Student.mdb";
String url = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=F:/Desktop/文档/word/Student.accdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "select * from Student";
ResultSet rs = statement.executeQuery(sql);
String name = "";
int age = 0;
while (rs.next()) {
name = rs.getString("name");
age = rs.getInt("age");
System.out.println("name::" + name);
System.out.println("age::" + age);
// statement.executeUpdate("update Student set name = '" + name
// + "345' where name = '" + name + "'");
}
rs.close();
connection.close();
} catch (Exception ex) {
System.out.println(ex);
System.exit(0);
}
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// ����Microsoft SQL server2000��2005��2008��ODBC
// String url = "jdbc:odbc:sql08";
// Connection connection =
// DriverManager.getConnection(url,"sa","qiaole");
// ����Microsoft Access2003��ODBC
// String url = "jdbc:odbc:accdb";
// String url =
// "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F:/Desktop/�ĵ�/word/Student.mdb";
String url = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=F:/Desktop/文档/word/Student.accdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "select * from Student";
ResultSet rs = statement.executeQuery(sql);
String name = "";
int age = 0;
while (rs.next()) {
name = rs.getString("name");
age = rs.getInt("age");
System.out.println("name::" + name);
System.out.println("age::" + age);
// statement.executeUpdate("update Student set name = '" + name
// + "345' where name = '" + name + "'");
}
rs.close();
connection.close();
} catch (Exception ex) {
System.out.println(ex);
System.exit(0);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |