MyEclipse Connecting to Oracle Database (must-see for beginners)

Source: Internet
Author: User

Preface: Just contact Oracle database, there is a need, write console program, realize the owner login. The database is Oracle. The following is a detailed description of the MyEclipse connection to the Oracle database.
Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;Importjava.sql.SQLException;ImportJava.util.Scanner; Public classORACLEJDBC { Public Static voidMain (string[] args) {//Instantiate keyboard inputScanner input =NewScanner (system.in); //Prompt for user nameSystem.out.println ("Please enter user name:"); String loginID=Input.next (); //prompt to enter a passwordSystem.out.println ("Please Enter password:"); String Password=Input.next (); //database name and login passwordString driver= "Oracle.jdbc.driver.OracleDriver"; String URL= "Jdbc:oracle:thin: @localhost: 1521:orcl"; String User= "Epet"; String pwd= "123456"; Connection Con=NULL; PreparedStatement PS=NULL; ResultSet RS=NULL; Try{class.forname (driver); Con=drivermanager.getconnection (URL,USER,PWD); //Writing SQL statementsString sql= "SELECT * from Master where loginid=? and password=? "; //get the result setps=con.preparestatement (SQL); Ps.setstring (1, loginID); Ps.setstring (2, password); RS=Ps.executequery (); if(Rs.next ()) {System.out.println ("Log in Success!!!" "); }Else{System.out.println ("User name or password error, Login failed!!!" "); }        } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(ClassNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); }              //Close resources in turn                Try {                    if(rs!=NULL) {rs.close (); } if(ps!=NULL) {ps.close (); }if(con!=NULL) {con.close (); }                }Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }                    }    }     

MyEclipse Connecting to Oracle Database (must-see for beginners)

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.