Use Jdbc-odbc to directly connect to the access file _ MySQL

Source: Internet
Author: User
For jsp servers set up in windows, and the system is relatively small, using access is a good choice, but to use an access database usually through the data source. Here we provide a method to directly connect to the data source without using the data source using java. The example program is as follows: importjava. SQL. *; publicclassAccess {publicstaticvoidmain (Strin AccessJDBCODBC

  
For jsp servers set up in windows, and the system is relatively small, using access is a good choice, but to use an access database usually through the data source. Here we provide a method to directly connect to the data source without using the data source using java. The example program is as follows:

Importjava. SQL .*;

PublicclassAccess

{

Publicstaticvoidmain (Stringargs [])

{

Try

{

Stringstrurl = "jdbc: odbc: driver = {MicrosoftAccessDriver (*. mdb)}; DBQ = books. mdb ";

Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");

Connectionconn = DriverManager. getConnection (strurl );

Statementstmt = conn. createStatement ();

Resultsetrs1_stmt.exe cuteQuery ("select * frombooks ");

If (rs. next ())

{

System. out. println (rs. getString ("Introduction "));

}

} Catch (effectione)

{

System. out. println (e );

}

}

}

You can see that you do not need to set the data source as long as you add an odbc driver to the driver. this method should also apply to other small databases (such as forpro.
(Source: CSDN)

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.