Use JDBC-ODBC to connect Access files directly

zhaozj2021-02-16  46

Use JDBC-ODBC to connect Access files directly

For settings with the JSP server under Windows, use Access is a better choice, but you should usually pass the data source using the Access database. Here is a method that does not directly connect the data source for Java using a data source. The example program is as follows:

Import java.sql. *;

Public Class Access

{

Public static void main (string args [])

{

Try

{

Strull = "JDBC: ODBC: driver = {Microsoft Access Driver (* .mdb)}; DBQ = BOOKS.MDB";

Class.Forname ("Sun.jdbc.odbc.jdbcodbcdriver");

Connection conn = drivermanager.getConnection (StrURL);

Statement Stmt = conn.createstatement ();

ResultSet RS = Stmt.executeQuery ("SELECT * from Books");

IF (rs.next ())

{

System.out.println (Rs.getstring ("Introduction"));

}

} catch (Exception E)

{

System.out.println (e);

}

}

}

You can see that you can also use the data source as long as the ODBC driver is added later, this method should also apply to other small databases (such as forpro).

转载请注明原文地址:https://www.9cbs.com/read-22598.html

New Post(0)