Examples of Java connections to Sybase and Oracle in Eclipse

Source: Internet
Author: User
Tags sybase

1. Connect Sybase

1) Preparatory work:

Prepare Sybase driver Jconn2.jar To reference this jar package in eclipse:

Right-click on the project >build path>add External Archives ..., find Jconn2.jar, click OK.

Note: There is an article on the internet, put Jconn2.jar into the CLASSPATH environment variable, this method in the command line with Javac manual compilation is feasible. It is necessary to introduce Jconn2.jar into the project in Eclipse.

2) A sample code

 Packageconndb;ImportJava.sql.*;Importjava.util.Properties; Public classDataswift { Public Static voidmain (String [] args) {Connection conn=NULL; Statement Statement=NULL; ResultSet RS=NULL; Try{class.forname ("Com.sybase.jdbc2.jdbc.SybDriver"); String URL= "Jdbc:sybase:tds:localhost:5000/cwbase15"; Properties Props=system.getproperties (); Props.put ("User", "sa"); Props.put ("Password", "Sasasa"); Conn=drivermanager.getconnection (url,props); Statement=conn.createstatement (); RS= Statement.executequery ("SELECT * from TEST");  while(Rs.next ()) {System.out.println (rs.getstring ("TEST")); }        }Catch(Exception e) {e.printstacktrace (); }finally{            Try{                if(rs!=NULL) Rs.close (); if(statement!=NULL) Statement.close (); if(conn!=NULL) Conn.close (); }Catch(Exception e) {e.printstacktrace (); }        }    }}
View Code

2. Connect Oracle

1) Preparatory work

Prepare the Oracle driver Ojdbc14.jar to reference this jar package in eclipse. method as above.

2) A sample code:

 Packageconndb;ImportJava.sql.*;Importjava.util.Properties; Public classconnoracle { Public Static voidmain (String [] args) {Connection conn=NULL; Statement Statement=NULL; ResultSet RS=NULL; Try{class.forname ("Oracle.jdbc.driver.OracleDriver"); String URL= "Jdbc:oracle:thin: @localhost: 1521:orcl"; Properties Props=system.getproperties (); Props.put ("User", "system"); Props.put ("Password", "abcd1234"); Conn=drivermanager.getconnection (url,props); Statement=conn.createstatement (); RS= Statement.executequery ("SELECT * from TEST");  while(Rs.next ()) {System.out.println (rs.getstring ("NAME")); }        }Catch(Exception e) {e.printstacktrace (); }finally{            Try{                if(rs!=NULL) Rs.close (); if(statement!=NULL) Statement.close (); if(conn!=NULL) Conn.close (); }Catch(Exception e) {e.printstacktrace (); }        }    }}
View Code

Examples of Java connections to Sybase and Oracle in Eclipse

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.