Tutorials to .com

Tutorials to .com » Jsp » Skills » JAVA + ACCESS programming experience

JAVA + ACCESS programming experience

Print View , by: iSee ,Total views: 25 ,Word Count: 414 ,Date: Fri, 21 Aug 2009 Time: 4:05 PM

Spent the afternoon time, the next experience programming java & access. In fact, the company's need to integrate data from two heterogeneous systems. Ms of a database using sql server, the other is access. In fact, data sheets for the operation, inevitably there is always an important process step. Before, the company has been using the sql server, database access operations are used to package javabean good, but most companies are actually doing so.
In terms of the programming for the sql server, Microsoft provides a special jdbc driver, that is, we usually used three jar files. However, access to the programming is not so luxurious, the programming is now available, simply provide a jdbc-odbc bridge to connect, efficiency, needless to say, oh.

Probably a bit wordy about the process:
1, the creation of the development of the database URL: At the same time, access the data source configuration
Such as: String url = "jdbc: odbc: Oblog";
2, load the driver
Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver");
3, to create connections
Connection conn = DriverManager.getConnection (url, "user", "pwd");
4, create a sql statement object
Statement stmt = conn.createStatement ();
5, the implementation of sql statement
stmt.execute (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.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 ();
)
)
)



Java skills and code Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.