程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SyBase數據庫 >> SyBase綜合文章 >> JConnect編程連接ASA示例

JConnect編程連接ASA示例

編輯:SyBase綜合文章
 This is document will assist newcomers in writing Java code to perform simple connectivity to an ASA database using the jConnect JDBC driver.

This article discusses a simple Java program which connects to an ASA database using the Sybase jConnect JDBC driver. Although simple, this code is commonly requested. Having this code at hand will prove as a handy reference. Further research into JDBC and the Java.sql package is highly recommended to better understand JDBC programming.

Here is the code necessary to connect to an ASA database via jConnect. This sample retrIEves a result set consisting of all the rows and columns of the employee table.

The myConnection code:

import Java.sql.*;

public class myConnection {

public static void main( String[] args ) {

try {
// Using Sybase jConnect 4.2
Class.forName("com.Sybase.jdbc.SybDriver");

// Using Sybase jConnect 5.2
//Class.forName("com.Sybase.jdbc2.jdbc.SybDriver");

Connection conn = DriverManager.getConnection("jdbc:Sybase:Tds:testMachine-pc:2638", "dba", "sql");
Statement stmt = conn.createStatement( );
ResultSet rs = stmt.executeQuery( "SELECT * FROM EMPLOYEE");
while ( rs.next( ) ) {
System.out.println( rs.getInt( 1 ) );
}
} catch ( Exception e ) {
System.out.println( "An exception occurred." );
}

} // end of main

} // end of MyConnection class


BrIEf explanation of the code:

In order to understand how this code works, important sections of code will be discussed.

Section 1:
import Java.sql.*;

This line of code is necessary to have Access to the database connectivity classes. The Java.sql package contains the connection, statement, and result set classes necessary to retrIEve and display data from a database.

Section 2:
// Using Sybase jConnect 4.2
Class.forName("com.Sybase.jdbc.SybDriver");

// Using Sybase jConnect 5.2
//Class.forName("com.Sybase.jdbc2.jdbc.SybDriver");

These two lines of code are used to dynam

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved