JAVA + ACCESS programming experience

Source: Internet
Author: User

In the afternoon, I spent some time programming java & access. In fact, the company needs to integrate the data of two heterogeneous systems. One database uses ms SQL server and the other is access. In fact, operations on data tables are always an important step in the program. Previously, the company had been using SQL server, and database access operations were encapsulated with javabean, and most companies actually did the same.

For programming, for SQL server, Microsoft provides a dedicated jdbc driver, that is, the three jar files that are commonly used. However, access programming is not so luxurious. Currently, the available programming methods only provide a jdbc-odbc bridge for connection, so the efficiency is not required.
  
The process is also a bit rough:
1. Create a database URL: configure the access data source at the same time.
For example, String url = "jdbc: odbc: Oblog ";
2. Load the driver
Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
3. Create a connection
Connection conn = DriverManager. getConnection (url, "user", "pwd ");
4. Create an SQL statement object
Statement stmt = conn. createStatement ();
5. Execute SQL statements
Stmt.exe cute (strSql. toString ());

Simply paste an example:


// Select. java

Import java. SQL .*;

Class Select {
Public static void main (){
Try {
String url = "jdbc: odbc: wombat ";
Connection conn = DriverManager. getConnection (url, "user", "pwd ");
Statement stmt = conn. createStatement ();
ResultSet rs = stmt.exe cuteQuery ("SELECT * FROM Table1 ");
System. out. println ("Got ResultSet Now ");
Rs. beforeFirst ();
While (rs. next ()){
System. out. println (rs. getString (1 ));
}
Stmt. close ();
Conn. close ();
}
Catch (Exception ex ){
Ex. printStackTrace ();
}

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.