MyEclipse connects to the Oracle database (required for beginners), myeclipseoracle

Source: Internet
Author: User

MyEclipse connects to the Oracle database (required for beginners), myeclipseoracle
As soon as I got started with Oracle databases, I had a need to write console programs to achieve master login. The database is Oracle. The following describes how to connect MyEclipse to the Oracle database in detail.

Import java. SQL. connection; import java. SQL. driverManager; import java. SQL. preparedStatement; import java. SQL. resultSet; import java. SQL. SQLException; import java. util. optional; public class oraclejdbc {public static void main (String [] args) {// input into the instantiated keyboard into new input (System. in); // prompt to enter the user name System. out. println ("Enter the User name:"); String loginid = input. next (); // prompt to enter the password System. out. println ("enter the password:"); Stri Ng password = input. next (); // Database Name and login password String 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); // write the SQL statement String SQL = "select * from master where loginid =? And password =? "; // Get the result set ps = con. prepareStatement (SQL); ps. setString (1, loginid); ps. setString (2, password); rs = ps.exe cuteQuery (); if (rs. next () {System. out. println ("Login successful !!! ");} Else {System. out. println (" the user name or password is incorrect. Login Failed !!! ") ;}} Catch (SQLException e) {// TODO Auto-generated catch block e. printStackTrace ();} catch (ClassNotFoundException e) {// TODO Auto-generated catch block e. printStackTrace ();} // close the resource try {if (rs! = Null) {rs. close () ;}if (ps! = Null) {ps. close () ;}if (con! = Null) {con. close () ;}} catch (SQLException e) {// TODO Auto-generated catch block 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.