Data | database
Java Connection Sybase Database
The first step: 工欲善其事, its prerequisite. (Download driver)
Download JDBC Driver:
URL: http://www.sybase.com/detail?id=1009726
There are two kinds of jConnect6.0 and jConnect5.5, we download 6.0 version.
Step two: Get the drive
Releases the downloaded Jconnect-6_0.zip file, which has a folder: Devclasses, with a jar file jconn3d under it. We will also release Jconn3d.jar, in fact, we can not release, in order to illustrate the simplicity, we will release it to any folder, such as: C:\Driver.
Step three: Set environment variables
Appends the above-released location directory, such as C:\Driver, to the tail of the environment variable CLASSPATH.
Fourth step: Everything is ready, only the east wind
All the preparations have been completed and you can start programming below. Let's take a simple database query for 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 for your database name
Properties sysprops = System.getproperties ();
Sysprops.put ("User", "user_id"); Set Database access User name
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 for one of the tables
ResultSet rs=stmt.executequery (SQL);
while (Rs.next ()) {
System.out.println (rs.getstring (2)); Get the value of the second column
}
}catch (Exception e)
{
Out.println (E.getmessage ());
}
}
}
[above program test pass]