Connect to the Sybase Database Using Java

Source: Internet
Author: User
Tags sybase sybase database

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: Id = 1009726
There are two types: jconnect6.0 and jconnect5.5. We will download version 6.0. Step 2: Get the driver
Download the 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: 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 ());

Related Article

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: 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.