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: 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 ());
  }
 }
}
[The above program has passed the test]
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: 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.