Connect to the Sybase Database Using Java
Step 1: to do good deeds, you must first sharpen your tools. (Download driver)
Download the JDBC driver:
URL: http://www.sybase.com/detail? Id = 1009726
There are two types: jconnect6.0 and jconnect5.5. We will download version 6.0.
Step 2: Get the driver
Download the jconnect-6_0.zip file, which contains the folder devclasses and the JAR file jconn3d. We also release jconn3d. jar, but it can not be released. For ease of instruction, we release it to any folder, such as C:/driver.
Step 3: Set Environment Variables
Append the released directory, such as C:/driver, to the end of the Environment Variable classpath.
Step 4
All the preparations have been completed. Now you can start programming. Take a simple database query as an example:
Import com. Sybase. jdbc3.jdbc. sybdriver;
Import java. SQL .*;
Import java. Io .*;
Import java. util .*;
Public class conntest {
Public static void main (string [] ARGs ){
Try {
Class. forname ("com. Sybase. jdbc3.jdbc. sybdriver"). newinstance ();
String url = "JDBC: Sybase: TDS: 192.168.100.252: 4500/mydb"; // mydb is your database name
Properties sysprops = system. getproperties ();
Sysprops. Put ("user", "user_id"); // set the database access Username
Sysprops. Put ("password", "user_pwd"); // Password
Connection conn = drivermanager. getconnection (URL, sysprops );
Statement stmt = conn. createstatement (resultset. type_scroll_sensitive, resultset. concur_updatable );
String SQL = "select * From userinfo"; // userinfo is a table.
Resultset rs1_stmt.exe cutequery (SQL );
While (Rs. Next ()){
System. Out. println (Rs. getstring (2); // obtain the value of the second column.
}
} Catch (exception E)
{
Out. println (E. getmessage ());
}
}
}