Home > Database > Mysql Tutorial > Java访问Access的一般方法介绍

Java访问Access的一般方法介绍

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:11:53
Original
1526 people have browsed it

import java.sql.*; public class AccessDB { String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String url = "jdbc:odbc:Driver={MicroSoft Access Driver *.mdb)};DBQ = Northwind.mdb"; String user = ""; String pwd = ""; Connection conn; Statement s

import java.sql.*;

public class AccessDB {

String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

String url = "jdbc:odbc:Driver={MicroSoft Access Driver

*.mdb)};DBQ = Northwind.mdb";

String user = "";

String pwd = "";

Connection conn;

Statement stmt;

ResultSet rs;

public MyDB() {

try {

Class.forName(driver);

} catch (Exception e) {

System.out.println(e);

}

}

//创建不可滚动的连接

public void connect() {

try {

conn = DriverManager.getConnection(url,user,pwd);

stmt = conn.createStatement();

} catch (Exception e) {

System.out.println(e);

}

}

//创建可以滚动的连接

public void connect2() {

try {

conn = DriverManager.getConnection(url,user,pwd);

stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

} catch (Exception e) {

System.out.println(e);

}

}

//关闭连接

public void close() {

try {

if (stmt != null) {

stmt.close();

}

if (conn != null) {

conn.close();

}

} catch (Exception e) {

System.out.println(e);

}

}

//查询语句

public ResultSet executeQuery(String sql) {

try {

if (stmt == null) {

connect();

}

rs = stmt.executeQuery(sql);

} catch (Exception e) {

System.out.println(e);

}

return rs;

}

}
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template