I created a simple class to test the communication to my localhost database, that I created with Mysql Workbench. The Mysql Server is running. The JDBC Driver is added to the Classpath of my project.
public class Database
{
public static void main(String[] args)
throws SQLException, ClassNotFoundException
{
Connection connection = null;
String serverName = "localhost:3306";
String databaseName = "detector_tests";
String url = "jdbc:mysql://" + serverName + "/" + databaseName
+ "?useSSL=TRUE";
String username = "simon";
String password = "password123";
connection = DriverManager.getConnection(url, username, password);
}
}
When I run the program I get the followning Exception:
Exception in thread "main"
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications
link failure
The last packet sent successfully to the server was 0 milliseconds
ago. The driver has not received any packets from the server. at
com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:172)
at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:444)
at
com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
at
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)
at java.sql.DriverManager.getConnection(Unknown Source) at
java.sql.DriverManager.getConnection(Unknown Source) at
Database.main(Database.java:17) Caused by:
com.mysql.cj.exceptions.CJCommunicationsException: Communications link
failure
The last packet sent successfully to the server was 0 milliseconds
ago. The driver has not received any packets from the server. at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source) at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
at
com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:103)
at
com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:149)
at
com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:165)
at
com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:355)
at
com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:789)
at
com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:499)
at
com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:217)
at
com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1411)
at com.mysql.cj.NativeSession.connect(NativeSession.java:165) at
com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:982)
at
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:852)
... 6 more Caused by: javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException:
java.security.cert.CertPathValidatorException: Path does not chain
with any of the trust anchors at
sun.security.ssl.Alerts.getSSLException(Unknown Source) at
sun.security.ssl.SSLSocketImpl.fatal(Unknown Source) at
sun.security.ssl.Handshaker.fatalSE(Unknown Source) at
sun.security.ssl.Handshaker.fatalSE(Unknown Source) at
sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source) at
sun.security.ssl.Handshaker.process_record(Unknown Source) at
sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) at
sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at
sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at
com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:213)
at
com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:206)
at
com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
at
com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:350)
... 13 more Caused by: java.security.cert.CertificateException:
java.security.cert.CertPathValidatorException: Path does not chain
with any of the trust anchors at
com.mysql.cj.protocol.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:280)
at
sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(Unknown
Source) ... 25 more Caused by:
java.security.cert.CertPathValidatorException: Path does not chain
with any of the trust anchors at
sun.security.provider.certpath.PKIXCertPathValidator.validate(Unknown
Source) at
sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(Unknown
Source) at java.security.cert.CertPathValidator.validate(Unknown
Source) at
com.mysql.cj.protocol.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:273)
... 26 more
It appears that I need to add some kind of certificate or something. I m not sure, because I m quite new to databases. Anyone with the same experience or a solution? If you need anymore information I'm happy to edit the post.
Thanks in advance!
Seems you are trying to connect mysql database along with a certificate. If you are connecting to MySQL instance through TLS, you need to have a trust store to keep your certificates. Refer to this document to create MySQL connection along with a TLS connection.
But, you can ignore TLS validation by setting FALSE for "useSSL" in MySQL connection URL. Your code will be as follows.
public class Database
{
public static void main(String[] args)
throws SQLException, ClassNotFoundException
{
Connection connection = null;
String serverName = "localhost:3306";
String databaseName = "detector_tests";
String url = "jdbc:mysql://" + serverName + "/" + databaseName
+ "?useSSL=FALSE";
String username = "simon";
String password = "password123";
connection = DriverManager.getConnection(url, username, password);
}
}
Hope this will be the answer to your question.
Related
I am trying to connect to mysql which is on google cloud using below code. This is my first attempt to work on google cloud sql using mysql.
public static void main(String[] args) throws IOException, SQLException {
String instanceConnectionName = "####";//providing correct connection name
String databaseName = "shan";
String username = "root";
String password = "####";//providing correct password
String jdbcUrl = String.format(
"jdbc:mysql://google/%s?cloudSqlInstance=%s&"
+ "socketFactory=com.google.cloud.sql.mysql.SocketFactory",
databaseName,
instanceConnectionName);
Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
try (Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery("SHOW TABLES");
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
}
}
}
When i try to execute this code, i am getting the below error:
Feb 25, 2018 4:45:41 PM com.google.cloud.sql.mysql.SocketFactory connect
INFO: Connecting to Cloud SQL instance [stockinventary-1517746804001:asia-east1:shan].
Feb 25, 2018 4:45:41 PM com.google.cloud.sql.core.SslSocketFactory getInstance
INFO: First Cloud SQL connection, generating RSA key pair.
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2271)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2024)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.sf.si.poc.ListTables.main(ListTables.java:48)
Caused by: java.lang.RuntimeException: Unable to obtain credentials to communicate with the Cloud SQL API
at com.google.cloud.sql.core.SslSocketFactory$ApplicationDefaultCredentialFactory.create(SslSocketFactory.java:549)
at com.google.cloud.sql.core.SslSocketFactory.getInstance(SslSocketFactory.java:140)
at com.google.cloud.sql.mysql.SocketFactory.connect(SocketFactory.java:48)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2192)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2225)
... 13 more
Caused by: java.io.IOException: Error reading credential file from location C:\Users\dell\AppData\Roaming\gcloud\application_default_credentials.json: Remote host closed connection during handshake
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getCredentialUsingWellKnownFile(DefaultCredentialProvider.java:251)
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredentialUnsynchronized(DefaultCredentialProvider.java:117)
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:91)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:191)
at com.google.cloud.sql.core.SslSocketFactory$ApplicationDefaultCredentialFactory.create(SslSocketFactory.java:547)
... 18 more
I also ran gcloud sql instances describe and it generated json file at: C:\Users\dell\AppData\Roaming\gcloud\application_default_credentials.json
Could you please guide me to figure out the actual cause of this issue and way to correct it?
I got the answer with my own analysis and here it is:
I added GOOGLE_APPLICATION_CREDENTIALS environment variable with json file(which was created when i run gcloud auth application-default login) as value.
This resolved my problem.
Thanks.
I was trying the below code to connect to an SFTP server
final String sftpURL = <<my hostname here>>;
final String username = <<username here>>;
final String password = <<password here>>;
SshParameters params = new SshParameters(sftpURL,username,password);
Sftp ftp = new Sftp(params);
// Connect, upload PNG images and release the connection.
ftp.connect();
ftp.disconnect();
When trying to connect it was throwing the below error:::
Exception in thread "main" com.jscape.inet.sftp.SftpException: SHA256 MessageDigest not available
at com.jscape.inet.sftp.SftpException.wrap(Unknown Source)
at com.jscape.inet.sftp.Sftp.a(Unknown Source)
at com.jscape.inet.sftp.Sftp.connect(Unknown Source)
at com.bcs.renewals.Test.main(Test.java:19)
Caused by: com.jscape.util.o.b: SHA256 MessageDigest not available
at com.jscape.util.o.b.a(Unknown Source)
at com.jscape.util.o.c.a(Unknown Source)
at com.jscape.inet.sftp.Sftp.b(Unknown Source)
... 2 more
Caused by: com.jscape.util.l.a.h: SHA256 MessageDigest not available
at com.jscape.inet.ssh.protocol.v2.connection.SessionConnector.connect(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.connection.SessionConnector.connect(Unknown Source)
at com.jscape.inet.sftp.SftpFileService3.actualStart(Unknown Source)
... 4 more
Caused by: com.jscape.util.l.a.b: SHA256 MessageDigest not available
at com.jscape.util.l.a.b.a(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.transport.TransportConnection.a(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.transport.TransportConnection.exchangeKeys(Unknown Source)
... 7 more
Caused by: java.security.NoSuchAlgorithmException: SHA256 MessageDigest not available
at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
at java.security.Security.getImpl(Security.java:695)
at java.security.MessageDigest.getInstance(MessageDigest.java:167)
at com.jscape.a.f.a(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.transport.keyexchange.DiffieHellmanGroupKeyExchange.createHash(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.transport.keyexchange.DiffieHellmanGroupClientKeyExchange.exchangeKeys(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.transport.TransportConnection.handle(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.messages.SshMsgKexInit.accept(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.messages.SshMsgKexInit.accept(Unknown Source)
at com.jscape.inet.ssh.protocol.v2.transport.TransportConnection.c(Unknown Source)
... 9 more
The above code was working few months before. But now its throwing the error. I have downloaded a latest version of sinet-factory.jar as well. Can some one please help me in solving the issue?
The issue was beacause it requires one more jar bcprov-ext-jdk15on-148.jar in the CLASSPATH along with the sinetfactory.jar
I added that and the problem resolved.
Thanks.
This question already has answers here:
InetAddress.getLocalHost() throws UnknownHostException
(9 answers)
Closed 6 years ago.
To develope a client applications, I need to read and modify worksheets and data in Google Sheets. I am facing with below issue:
SpreadsheetService service = new SpreadsheetService("sheet1");
String sheetUrl = "https://spreadsheets.google.com/feeds/list/1XP3KQTboWCArbvH99XYEGsVOldc97NqFzKD MiEepXRA/default/public/values"; //Sheet url
URL url = new URL(sheetUrl); // Get Feed of Spreadsheet url
ListFeed lf = service.getFeed(url, ListFeed.class); //Error statement
Issue:
java.net.UnknownHostException: spreadsheets.google.com at
java.net.AbstractPlainSocketImpl.connect(Unknown Source) at
java.net.PlainSocketImpl.connect(Unknown Source) at
java.net.SocksSocketImpl.connect(Unknown Source) at
java.net.Socket.connect(Unknown Source) at
sun.security.ssl.SSLSocketImpl.connect(Unknown Source) at
sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source) at
sun.net.NetworkClient.doConnect(Unknown Source) at
sun.net.www.http.HttpClient.openServer(Unknown Source) at
sun.net.www.http.HttpClient.openServer(Unknown Source) at
sun.net.www.protocol.https.HttpsClient.(Unknown Source) at
sun.net.www.protocol.https.HttpsClient.New(Unknown Source) at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown
Source) at
sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown
Source) at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown
Source) at
sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown
Source) at
com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:503)
at
com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135) at
com.google.gdata.client.Service.getFeed(Service.java:998) at
com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
at com.google.gdata.client.Service.getFeed(Service.java:1017) at
test_project.test_demo.main(test_demo.java:35)
As stated here, UnknownHostException means that your device was not able to resolve the host name. It emerges when you are trying to connect to a remote host using its host name, but the IP address of that host cannot be resolved. From this blog, you should check the input of Socket (or any other method that throws an UnknownHostException), and validate that it is the intended one. If you are not sure whether you have the correct host name, you can launch a terminal and use the nslookup command to see if your DNS server can resolve the host name to an IP address successfully.
If that doesn’t work, you should check if the host name you have is correct and then try to refresh your DNS cache. If that doesn’t work either, try to use a different DNS server, eg Google Public DNS is a very good alternative.
You can also check on this link. Hope this helps!
I'm trying to make a Java program communicate with a MySQL server hosted with A Small Orange. The IP and port they provided me with are 129.121.106.234:3306. The user has been given full permissions to the database, and in my CPanel I've allowed all remote hosts to connect to the MySQL database by adding the access host "%".
I'm using Eclipse, and I've downloaded and added the JDBC driver to the build path.
As near as I can tell, the user I'm trying to use has full permissions to the database, and the MySQL server is open to any request from any IP. I've also tried my admin MySQL credentials, with the same error, so I'm decently confident the issue is with my code. Not absolutely sure though, since I'm not hosting the MySQL server myself.
My code:
package com.package.IPBounce;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Main {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
* Isaac the Support Ninja says: The MySQL port is 3306. The IP you use
* is 129.121.106.234.
*/
URL whatismyip;
String IP;
try {
whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
IP = in.readLine();
System.out.println(IP);
Connection con = null;
Statement st = null;
ResultSet rs = null;
//this is just testing code until I get the connection working
String url = "jdbc:mysql://129.121.106.234:3306/db_name";
String user = "user_name";
String password = "small_password";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url, user, password);//error is on this line
st = con.createStatement();
rs = st.executeQuery("SELECT VERSION()");
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The error text:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2504)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2541)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2323)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.package.IPBounce.Main.main(Main.java:39)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 15 more
Edit: I found the solution. My hosting service was blocking the MySQL requests at the firewall. Cleared that up, now it works wonderfully.
The only thing I see as a possible issue is the "newInstance()" call. Try remove that and see if that works.
From:
Class.forName("com.mysql.jdbc.Driver").newInstance();
To:
Class.forName("com.mysql.jdbc.Driver");
This question has been answered here:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Please try the steps in the accepted answer and see if your issue is resolved.
From my experience, I had this issue when my MySql configuration file allowed only localhost access. Replace localhost with the ip address.
import java.sql.*;
public class one {
public static void main(String[] args)
{
Connection conn=null;
Statement stmt=null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:#//localhost:1521/ecom","system","manager");
stmt=conn.createStatement();
String str="insert into country values(3,'bangladesh');";
int k=stmt.executeUpdate(str);
System.out.println(k);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
The only jar file I added to the class path is ojdbc6.jar is there any other jar required for connecting with oracle 11g(11.2.0.1.0) I am using eclipse as IDE
here are the errors
java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at one.main(one.java:17)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:237)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocket`Impl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:141)
1) Please be sure database host name, port number, or database instance name are correct.
2) Be sure the TNSListener has been started ( run lsnrctl start)
The connection string is malformed. It should be
"jdbc:oracle:thin://#localhost:1521/ecom"
Notice the transposition of // and #.