Java Connection Sybase Database

Source: Internet
Author: User
Tags stmt sybase sybase database
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]



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.