Using Access as a database

Source: Internet
Author: User

1 ImportJava.sql.*;2 3  Public classconnectaccess {4 5     6      Public Static voidMain (String args[]) {7Connectaccess CA =Newconnectaccess ();8         Try {9 ca.connectaccess ();Ten}Catch(Exception e) { One e.printstacktrace (); A         } -     } -  the      Public voidConnectaccess ()throwsException { -Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver"); -          -         /** + * Connect directly to an Access file.  -          */ +String url = "Jdbc:odbc:driver=microsoft Access DRIVER (*.mdb, *.accdb);D bq=access\\access.accdb; pwd=123456; "; A          at         /** - * Using ODBC to connect data sources -          */ - //String ur1 = "Jdbc:odbc:DataSource"; -          -Connection conn = drivermanager.getconnection (URL, "", ""); inStatement stmt =conn.createstatement (); -String sql = "SELECT * FROM T_system_user_info"; toResultSet rs =stmt.executequery (SQL); +          while(Rs.next ()) { -System.out.println (Rs.getstring (2)); theSystem.out.println (Rs.getstring (3)); *         } $ rs.close ();Panax Notoginseng stmt.close (); - conn.close (); the     } +  A}

For learning reference only.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.