Java+access Programming Experience

Source: Internet
Author: User
Tags odbc stmt
Access| programming in the afternoon spent a little time, experience the next java&access programming. In fact, the company needs to integrate data from two heterogeneous systems. The database is a SQL Server with MS and the other is access. In fact, the operation of the data table is always an important step in the program. Previously, the company had been using SQL Server, and the database access operations were encapsulated with JavaBean, and most companies actually did the same.
In terms of programming, Microsoft provides a dedicated JDBC driver for SQL Server, which is the three jar files that everyone uses. But access's programming is not so luxurious, now available programming methods, just provide a JDBC-ODBC bridge to connect, the efficiency is needless to say oh.
  
Probably the process also a bit wordy:
1, create a URL to the database: Configure the Access data source at the same time
such as: String URL = "Jdbc:odbc:Oblog";
2, load Driver
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
3, create the connection
Connection conn = drivermanager.getconnection (URL, "user", "pwd");
4, create the SQL statement object
Statement stmt = Conn.createstatement ();
5, execute the SQL statement
Stmt.execute (Strsql.tostring ());

Simply put 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.executequery ("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 ();
}
}
}


Related Article

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.