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 ();}}}