简体   繁体   中英

Can't start sql db in 11g through jdbc.Getting java sql exception

import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;
import java.sql.Statement;
import java.util.Properties;
import oracle.jdbc.OracleConnection;

public class Test {

static final String url2= "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP 

(HOST=192.168.1.171)(PORT=5521))"+"(CONNECT_DATA =(SERVICE_NAME = rdbms)))";

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

            OracleDataSource ds = new OracleDataSource();
           Properties prop = new Properties();
           prop.setProperty("user","system");
           prop.setProperty("password","manager");
           prop.setProperty("internal_logon","sysdba");
           prop.setProperty("prelim_auth","true");
           ds.setConnectionProperties(prop);
           ds.setURL(url2);
           OracleConnection conn = (OracleConnection)ds.getConnection();
           conn.startup(OracleConnection.DatabaseStartupMode.NO_RESTRICTION);
           conn.close();
    }
}

getting

Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

Can anyone help with this?

Cause:
The listener received a request to establish a connection to a database or other service. The connect descriptor received by the listener specified a service name for a service (usually a database service) that either has not yet dynamically registered with the listener or has not been statically configured for the listener. This may be a temporary condition such as after the listener has started, but before the database instance has registered with the listener.

Action: - Wait a moment and try to connect a second time.

  • Check which services are currently known by the listener by executing: lsnrctl services

  • Check that the SERVICE_NAME parameter in the connect descriptor of the net service name used specifies a service known by the listener.

  • If an easy connect naming connect identifier was used, check that the service name specified is a service known by the listener.

  • Check for an event in the listener.log file.

You must understand that when it comes to exceptions, many times JDBC simply serves as a wrapper to errors that occur at the DB side,
or propagates driver specific (ie - postgresql jdbc driver, oracle jdbc driver) specific errors.
You should google the error and you will find what I believe is a clear explanation:
http://ora-12514.ora-code.com/ .
If you see one of the suggestions there is to retry after a few seconds and reconnect again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM