Oracle.jdbc.driver.OracleDriver () no error exists

I am trying to execute sql command from a java program. I have no errors regarding this code ... but I ran into communication failures from the database.

import java.sql.*; public class DBCreateTable { public static void main(String args[]) throws Exception { DriverManager.registerDriver (new Oracle.jdbc.driver.OracleDriver()); Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","lms","abc"); Statement stmt=con.CreateStatement(); stmt.executeUpdate("create table emp(eno number(5),name varchar2(20))"); } } 

Errors encountered:

 Exception in thread "main" java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=185599488)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333) at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404) at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja va:468) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314) at java.sql.DriverManager.getConnection(DriverManager.java:579) at java.sql.DriverManager.getConnection(DriverManager.java:221) at DBCreateTable.main(DBCreateTable.java:7) 

In my sql commands, I did the following.

  SQL> connect system/tiger; SQL> create user lms identified by abc; SQL> grant connect,resource to lms; 

and plz tell me what a scott tiger is. I was busy a lot there .. what users have .. what to unlock and how? plz thanks ..

+4
source share
4 answers

Add the oracle driver drum to the project build path and it should work. (e.g. http://mirrors.ibiblio.org/pub/mirrors/maven/mule/dependencies/maven1/oracle-jdbc/jars/ojdbc14.jar )

+7
source

The name of your package is incorrect.

 DriverManager.registerDriver (new **Oracle**.jdbc.driver.OracleDriver()); 

In java, a package name always starts with an uncapitalized letter. Your program error in compilation time .

0
source

The oracle.jdbc.driver classes. *, theojdbc4.jar and the OracleConnectionCacheImpl class are no longer supported or are not available in Oracle 11g. So use oracle.jdbc.oracledriver instead.

0
source

Karjala you downloaded the Oracle JDBC drivers, first download them, you can download the Oracle JDBC drivers here http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html Choose the version that suits your version Database.

Java program to connect to Oracle: The following Java program uses the Oracle JDBC driver to connect to an executable instance of an Oracle database. You can use this program in any Oracle database, as this example uses the built-in DUAL Dracy table to get the system date. DUAL allows you to retrieve values ​​such as the system date using a regular SQL query.

1 // Java program example - connecting to an Oracle database 2 import java.sql.Connection; 3 import java.sql.Date; 4 import java.sql.DriverManager; 5 import java.sql.ResultSet; 6 import java.sql.SQLException; 7 import java.sql.Statement; eight

9 public class OracleSample {10

11 public static final String DBURL = "jdbc: oracle: thin: @localhost: 1521: XE"; 12 public static final String DBUSER = "system"; 13 public static final String DBPASS = "manager"; 14

15 public static void main (String [] args) throws SQLException {16

17 // Download the Oracle JDBC driver 18 DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ()); 19

20 // Connection to the Oracle database 21 Connection con = DriverManager.getConnection (DBURL, DBUSER, DBPASS); 22

23 Statement statement = con.createStatement (); 24

25 // Executing a SELECT query in a DUAL DUAL Table. Useful for getting system values ​​26 // Allows us to get values ​​as if the query from table 27 ResultSet rs = statement.executeQuery ("SELECT SYSDATE FROM DUAL"); 28

29th

30 if (rs.next ()) {31 Date currentDate = rs.getDate (1); // returns the first column 32 System.out.println ("Current date from Oracle:" + currentDate); 33} 34 rs.Close (); 35 statement.close (); 36 con.close (); 37} 38}

Hope this helps you guys ....... :-)

-2
source

Source: https://habr.com/ru/post/1398983/


All Articles