Unable to connect to Google cloud SQL via Java eclipse - java

I'm having trouble to connect to my database from eclipse using my instance a google cloud sql database.
I successed to access to the database via mysql command line but no in eclise.
My code:
String instanceConnectionName = "****";
String databaseName = "****";
String username = "***";
String 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);
The Error I get:
jdbc:mysql://google/****?cloudSqlInstance=****e&socketFactory=com.google.cloud.sql.mysql.SocketFactory
May 03, 2017 10:53:07 AM com.google.cloud.sql.mysql.SocketFactory connect
INFO: Connecting to Cloud SQL instance [****].
May 03, 2017 10:53:07 AM com.google.cloud.sql.mysql.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:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2332)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
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:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at neviTracker.program.ProgramConnections.main(ProgramConnections.java:27)
Caused by: java.lang.RuntimeException: Unable to obtain credentials to communicate with the Cloud SQL API
at com.google.cloud.sql.mysql.SslSocketFactory$ApplicationDefaultCredentialFactory.create(SslSocketFactory.java:545)
at com.google.cloud.sql.mysql.SslSocketFactory.getInstance(SslSocketFactory.java:138)
at com.google.cloud.sql.mysql.SocketFactory.connect(SocketFactory.java:47)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)
... 13 more
Caused by: java.io.IOException: The Application Default Credentials are not available. They are available if running on Google App Engine, Google Compute Engine, or Google Cloud Shell. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:98)
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.mysql.SslSocketFactory$ApplicationDefaultCredentialFactory.create(SslSocketFactory.java:543)
... 18 more

You have an error message that says the environment variable GOOGLE_APPLICATION_CREDENTIALS is not set. Please create a .credentials file in a root folder and add your credential details in it.
Please refer to this link
https://developers.google.com/identity/protocols/application-default-credentials

The Application Default Credentials are not available. They are available if running on Google App Engine, Google Compute Engine, or Google Cloud Shell. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
You need credentials to access google cloud sql. You can create from here
After creating your credential, create your key file and point it in your bash_profile(read the block quote for more info). then it should work
Alternatively you can use CLOUD SQL PROXY to not work with environment variables, follow the steps in this link, if something is blurry please ask.
https://cloud.google.com/sql/docs/mysql/connect-admin-proxy
hope this helps.

Related

Java JDBC getting Postgres socket timeout exception for allowed connection

I have two virtual machines where one is hosting postgres DB and another application that is connecting to database. I have tried multiple configuration ways, but every time connecting I'm connecting via JDBC I get:
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225)
at org.postgresql.Driver.makeConnection(Driver.java:465)
at org.postgresql.Driver.connect(Driver.java:264)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
at java.base/java.net.Socket.connect(Unknown Source)
at org.postgresql.core.PGStream.createSocket(PGStream.java:231)
at org.postgresql.core.PGStream.<init>(PGStream.java:95)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
For now in my pg_hba.conf file I have configured application host with:
host my_db user 192.168.14.147/32 password (tried md5 and even trust, same result)
I have also checked postgresql.conf and I have
listen_addresses = '*'
I have reloaded conf in db with:
SELECT pg_reload_conf();
My postgresql server is working on host 192.168.44.38. Before I've added pg_hba.conf configuration I was getting error about no entry in this file and I also tried to connect to DB via pgAdmin and it works, so my config should be okay.
My jdbc connection method:
try {
String postgresConnectionUrl = "jdbc:postgresql://192.168.44.38:5432/my_db";
Connection connection = DriverManager.getConnection(postgresConnectionUrl, "user", "my_pass");
return connection;
} catch (SQLException sqlException) {
log.error("Error connecting. ", sqlException);
return null;
}
I've found nothing in postgres logs, also my user account has no limited connections and isn't even used.

Java MySql PoolableConnectionFactory &

I have a working code, which works fine on two other machines. those machines have local mysql server instances running on them.
Now procured a new machine and installed Mysql server on this and am trying to run the same code, which works fine in other machines. But getting the poolable connection factory error. pasting the whole error for your reference.
ensured that max_connections is over 1K and have set appropriate variables correctly. But still not able to connect to DB.
Used latest MySql connector, however still facing the issue.
Am able to connect to Sql from the terminal and from workbench, however, the problem occurs only when trying to connect to MySQL from eclipse using java.
I vaguely remember me facing the same issue on other machines, when mysql was freshly installed, however, I couldn't remember the solution. The issue was with some mysql Variable, which was causing the issue.
Could someone help me out on how this problem could be resolved? which variables need to be changed.
java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2291)
at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2038)
at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1533)
at com.Common.Handles.Td_Mmm_Data.getConnection(Td_Mmm_Data.java:71)
at com.TD.TableOperations.asdf.asdfghj(TBLO_ORDERS.java:141)
at poe.P4_DBDataAnalyzers.Engines.asdfghjk.getAllCsRecos(UpdateAllcs.java:230)
at poe.P4_DBDataAnalyzers.Engines.asdfghjk.UpdateCsRecos(UpdateAllcs.java:52)
at Alpha.EnginesManager.asdfghjk(EnginesManager.java:132)
at Alpha.PreOpenEngines.main(PreOpenEngines.java:19)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
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:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2165)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2090)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
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:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:39)
at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:256)
at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2301)
at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2287)
... 8 more
Caused by: java.lang.NullPointerException
at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3005)
at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1916)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1845)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2106)
... 22 more
Exception in thread "main" java.lang.NullPointerException
at com.Common.Handles.Td_Mmm_Data.closeConnection(Td_Mmm_Data.java:96)
at com.TD.TableOperations.qwerqwer.GetAllEntriesAsList(TBLO_ORDERS.java:150)
at poe.P4_DBDataAnalyzers.Engines.qwerqwerqwerweqr.getAllCsRecos(UpdateAllcsRecosManager.java:230)
at poe.P4_DBDataAnalyzers.Engines.qwerqewrqewwqerqwerqwer.Updatecs(UpdateAllCs.java:52)
at Alpha.EnginesManager.qwerweqqwerqwer(EnginesManager.java:132)
at Alpha.PreOpenEngines.main(PreOpenEngines.java:19)
Worked through line by line and checked everything. Solved the problem Finally.
Multiple projects were added to the project. There were some references to old MySql connector.
Some changes in MySql 8.0 and above and needed the flag "&allowPublicKeyRetrieval=true" which was causing connectivity issues.
In addition, Max_Connections in mysql variables needed to be changed. Connection Time out settings needed to be tweaked.
Thank you all for your inputs.

Mysql Access denied for user 'user'#'localhost' (using password: yes) "openshift"

i want to connect to mysql database hosted in openshift server using java.
everything works fine on my local computer but when i try connect to openshift database i am getting this error
java.sql.SQLException: Access denied for user : 'userEl'#'#localhost' (using password: yes)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:795)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:44)
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:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at myjava.Test.main(Test.java:13)
here is my code
public class Test {
public static void main(String[] args) {
String state;
try {
Connection con = DriverManager.getConnection("jdbc:mysql://ip/mydb","userEl","password");
Statement stm= con.createStatement();
ResultSet rs= stm.executeQuery("SELECT * FROM server");
while(rs.next()){
state=rs.getString(1);
System.out.println("state = "+ state);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
When using the OpenShift Online MySQL cartridge, you can not login as "root" or as a 'user'#'localhost'. You must login with the credentials that are provided to you by OpenShift when installing the MySQL cartridge. You can view the credentials by sshing into your gear and running the command env | grep MYSQL, or you can view them in the OpenShift Online Web Console. For more information about using MySQL on OpenShift Online, please refer to this document (https://developers.openshift.com/databases/mysql.html) in the Developer Portal.

Check MS SQL connection Encryption strength/length (for JDBC)

When connecting with Java (IBM JRE 1.6 or 1.7) and MS JDBC Driver 4.0.2206.100 the login is for sure or entire connection is encrypted (SSL/TLS or TDS or ??). (Default of driver encrypt = false or blank info here; MS JDBC blog info here)
Some instance working fine some give error "RSA premaster secret error" (entire Stack Trace below). All MS SQL instance have no SSL enabled.
When using the IBM Java Cryptography Extension (JCE) Unlimited Strength (US export restrictions) I can also connect to the instance which gave me before the RSA secret error before.
It seems that the difference of MS SQL instances is the "Log on as" user (different Domain user)
Question 1: How do I find details about the encryption/certificate (length/strength/...)?
On MS SQL without SSL enabled how to identify what cert is used for the JDBC connection
Tested with Squirrel and IBM tool(both with IBM Java).
Squirrel with Oracle JRE 1.8 works right away without using unlimited strength JCE
DB is MS SQL 2012 SP2 if that matters.
Full Stack trace of error (IBM JRE not using unlimited strength JCE)
000000c0 DSConfigurati W DSRA8201W: DataSource Configuration: DSRA8040I: Failed to connect to the DataSource null. Encountered java.sql.SQLException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "RSA premaster secret error". ClientConnectionId:a5af5544-1768-49bc-b91d-87169cd06306 DSRA0010E: SQL State = 08S01, Error Code = 0.
java.sql.SQLException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "RSA premaster secret error". ClientConnectionId:a5af5544-1768-49bc-b91d-87169cd06306 DSRA0010E: SQL State = 08S01, Error Code = 0
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1668)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1323)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnectionInternal(SQLServerDataSource.java:621)
at com.microsoft.sqlserver.jdbc.SQLServerPooledConnection.createNewConnection(SQLServerPooledConnection.java:60)
at com.microsoft.sqlserver.jdbc.SQLServerPooledConnection.<init>(SQLServerPooledConnection.java:42)
at com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource.getPooledConnection(SQLServerConnectionPoolDataSource.java:34)
at com.ibm.ws.rsadapter.DSConfigHelper$1.run(DSConfigHelper.java:1273)
at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5477)
at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5603)
at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
at com.ibm.ws.rsadapter.spi.ServerFunction$6.run(ServerFunction.java:567)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.rsadapter.DSConfigHelper.getPooledConnection(DSConfigHelper.java:1288)
at com.ibm.ws.rsadapter.DSConfigHelper.getPooledConnection(DSConfigHelper.java:1196)
at com.ibm.ws.rsadapter.DSConfigurationHelper.getConnectionFromDSOrPooledDS(DSConfigurationHelper.java:2075)
at com.ibm.ws.rsadapter.DSConfigurationHelper.getConnectionFromDSOrPooledDS(DSConfigurationHelper.java:1951)
at com.ibm.ws.rsadapter.DSConfigurationHelper.testConnectionToDataSource(DSConfigurationHelper.java:1763)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.ibm.ws.management.DataSourceConfigHelperMBean.testConnectionToDataSource(DataSourceConfigHelperMBean.java:330)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:272)
at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1152)
at java.security.AccessController.doPrivileged(AccessController.java:388)
at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30)
at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:41)
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1146)
at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:999)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:847)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:783)
at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1350)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1243)
at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.ibm.ws.management.connector.soap.SOAPConnector.invoke(SOAPConnector.java:488)
at com.ibm.ws.management.connector.soap.SOAPConnector.service(SOAPConnector.java:322)
at com.ibm.ws.management.connector.soap.SOAPConnection.handleRequest(SOAPConnection.java:65)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:733)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:522)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1881)
Caused by: javax.net.ssl.SSLKeyException: RSA premaster secret error
at com.ibm.jsse2.kb.<init>(kb.java:86)
at com.ibm.jsse2.mb.a(mb.java:419)
at com.ibm.jsse2.mb.a(mb.java:71)
at com.ibm.jsse2.lb.t(lb.java:241)
at com.ibm.jsse2.lb.a(lb.java:3)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:855)
at com.ibm.jsse2.SSLSocketImpl.h(SSLSocketImpl.java:320)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:676)
at com.ibm.jsse2.SSLSocketImpl.startHandshake(SSLSocketImpl.java:620)
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1618)
... 55 more
Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
at javax.crypto.Cipher.a(Unknown Source)
at javax.crypto.Cipher.a(Unknown Source)
at javax.crypto.Cipher.a(Unknown Source)
at javax.crypto.Cipher.init(Unknown Source)
at com.ibm.jsse2.kb.<init>(kb.java:115)
... 64 more
============== Update: ==============
SQL locates/pick cert based on the name (see this MS support link from Sep 12, 2008)
SQL Server looks at the certificate store to find a certificate with the same name as the Fully Qualified Domain Name System (FQDN) of the SQL Server computer name
so if server has cert with matching name it will try to use it. If that cert using stronger enc than supported by the JRE/JDK you will get the above error message
Also check this reg key (modify MSSQL11.MSSQLSERVER part for your instance/version)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQLServer\SuperSocketNetLib
here PS to check
Get-ItemProperty "hklm:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQLServer\SuperSocketNetLib"
I would suggest running your tests with -Djavax.net.debug=all if this option works for IBM JDK. If not, try to find a similar option for IBM JDK. As a last resort use network packet sniffer.
This way you can get an idea who is complaining: the SQL server or the JDK running you client.
I would also try to run the same test under Oracle JDK if possible or under OpenJDK. This way you can pinpoint the cause of the problem.

getting an error while connecting to sql server 2008 enterprise edition

i am trying to connect with sql server 2008 using java connection string but i am getting following error
jdbc:sqlserver://127.0.0.1:1434;DatabaseNameconnect?autoReconnect=true
com.microsoft.sqlserver.jdbc.SQLServerException: The server version is not supported. The target server must be SQL Server 2000 or later.
com.microsoft.sqlserver.jdbc.SQLServerException: The server version is not supported. The target server must be SQL Server 2000 or later.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.DBComms.Prelogin(Unknown Source)
at com.microsoft.sqlserver.jdbc.DBComms.(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.dnb.discovery.connection.ConnectionBean.makeMsSqlConnection(ConnectionBean.java:56)
at com.dnb.discovery.factory.MssqlDAOFactory.(MssqlDAOFactory.java:18)
at com.dnb.discovery.dao.mssqldao.MssqlCompanyDAO.(MssqlCompanyDAO.java:8)
at com.dnb.discovery.relevance.Relevance.(Relevance.java:26)
at com.dnb.discovery.dao.SolrDAO.readDataFromSolr(SolrDAO.java:189)
at com.dnb.discovery.searchservice.SearchService.buyerTextSearchAnonymous(SearchService.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:210)
at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(InvokerTube.java:132)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:241)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:74)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:581)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:540)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:525)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:422)
at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:226)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:375)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:175)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:100)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:77)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:65)
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:65)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:68)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:555)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:65)
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:527)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
i am using following jar for connection
sqljdbc-2005-1.0.jar
please help
You're using a SQL Server 2005 JDBC driver, but talking to SQL Server 2008. While I would have expected that to work, I suspect the best approach would probably be to update your JDBC driver:
Download page for the latest MS JDBC driver

Categories