Java. SQL. sqlexception: Io exception: Connection refused (description = (TMP =) (vsnnum = 169869568) (ERR = 12505) (err

Source: Internet
Author: User
Tags oracleconnection

The following exception occurs when connecting to the database using JDBC: Java. SQL. sqlexception: Io exception: Connection refused (description = (TMP =) (vsnnum = 169869568) (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. (oracleconnection. java: 404) at oracle. JDBC. driver. oracledriver. getconnectioninstance (oracledriver. java: 468) at oracle. JDBC. driver. oracledriver. connect (oracledriver. java: 314) at java. SQL. drivermanager. getconnection (unknown source) at java. SQL. drivermanager. getconnection (unknown source) at XX. testcon. main (testcon. java: 17)

 

This indicates thatSid_name Error: JDBC: oracle: thin :@192.168.1.2: 1521:Sid_name, Please checkSid_name,

Because my database is oracleservicedhy, we can see that the SID set for installation at that time is dhy. Now, change the Code as follows:

Try {
// Step1.add drives
Class. forname ("oracle. JDBC. Driver. oracledriver ");
// Step2.get connection
Connection conn = drivermanager. getconnection ("JDBC: oracle: thin: @ 127.0.0.1: 1521:Dhy"," Scott "," Tiger ");
// Step3.creat statement
Statement Sm = conn. createstatement ();
// Step4.result set
Resultset rs1_sm.exe cutequery ("select * from EMP ");
While (Rs. Next () {// has next
System. Out. println ("username:" + Rs. getstring (2 ));
}
}
Catch (exception e ){
E. printstacktrace ();
}

Test Run, OK!

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.