Connecting Oracle Databases in Java

Source: Internet
Author: User

I just finished the system today. wrote an Oracle data Connectivity test but reported a bad version number in class file error, the online discovery is a JDK setup problem. MyEclipse defaults to jdk5.0 and the environment I run is set jdk6.0 ....

Workaround Configure the MyEclipse jer steps: Window-> preferences->java-> installed jre-> Select-> Edit->jre home directory-> browse-> find jdk1.6 Installation path automatically load- >ok

Run it again, fix it.

The code is as follows:

Import java.sql.*;

Public class Orcldemo {
 public static void Main (string[] args) {
  try {
    Load driver
   class.forname ("Oracle.jdbc.driver.OracleDriver");
   // Create connection Note URL path "jdbc:oracle:thin:@+" host: "+post+": "+sid
   //host represents the IP or domain name of the server on which the database resides;
    //post indicates the server port number Oracle defaults to 1521
   //sid to the database identity (database name)
in the server     Connection conn = drivermanager.getconnection (
      "Jdbc:oracle:thin: @localhost: 1521 : Jzbr ", Scott", "Tiger");    
   string sql = "SELECT * from emp";
  & nbsp Statement stmt = Conn.createstatement ();
   resultset rs = stmt.executequery (SQL);
   while (Rs.next ()) {
    system.out.println (Rs.getint (1));
     system.out.println (rs.getstring (2));

}
Rs.close ();
Stmt.close ();
Conn.close ();
catch (ClassNotFoundException e) {

E.printstacktrace ();
catch (SQLException e) {
E.printstacktrace ();
}

}

}


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.