I have the following java code.
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/shincy_intrn","shincy_intrn","shincy");
Statement st=con.createStatement();
int result=st.executeUpdate("insert into test(name)values('Swapna')");
if(result>0)
System.out.println("Inserted");
When I execute the code, I got the following exception,
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Bad handshake
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4098)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4030)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:951)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1717)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1276)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2389)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2422)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2207)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TestDb.main(TestDb.java:17)
I am using eclipse and mysql5.5.38 on linux server
Make sure the directory and files all have the same file/directory ownership.
I had this issue while upgrading gerrit and tried all possibilities and finally found that some of the directories and files under gerrit were owner by root and not the user with which am starting gerrit.
chmod -R user:group *
Related
While I am running JUnit file I am getting the following type of error.
Here is the complete stacktrace below:
org.powermock.reflect.exceptions.FieldNotFoundException: Field 'fTestClass' was not found in class org.junit.internal.runners.MethodValidator.
at org.powermock.reflect.internal.WhiteboxImpl.getInternalState(WhiteboxImpl.java:643)
at org.powermock.reflect.Whitebox.getInternalState(Whitebox.java:308)
at org.powermock.modules.junit4.internal.impl.testcaseworkaround.PowerMockJUnit4MethodValidator.validateTestMethods(PowerMockJUnit4MethodValidator.java:79)
at org.powermock.modules.junit4.internal.impl.testcaseworkaround.PowerMockJUnit4MethodValidator.validateInstanceMethods(PowerMockJUnit4MethodValidator.java:49)
at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:51)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.validate(PowerMockJUnit44RunnerDelegateImpl.java:108)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:70)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:144)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:39)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:111)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:59)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
I am using
junit 4.12 jar,
powermock-api-mockito 1.6.6 jar,
powermock-module-junit4 1.6.6 jar,
powermock-module-junit4 common 1.6.6 jar,
powermock-core 1.6.6 jar
Can anyone help me to resolve this issue ?
I have created a user with all privileges. Bit confused in selecting Host(currently localhost),
Hibernate setting are.
jdbc.driverClassName = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://67.3.234.45:3306/user
jdbc.username = username
jdbc.password = password
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = true
hibernate.hbm2ddl.auto = update
exception is : Updated the question with full exception..
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(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1038)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2237)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2270)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2069)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:155)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:219)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:203)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:522)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
First: phpmyadmin is a tool for administring databases. It seems to be completely irrelevant to the question. (Although it might be useful for debugging)
In order to debug this issue, double check that the following are correct:
host
port
Database name
username
password
Double check that you can actually access the server, e.g. by pinging it, or by using telnet to connect to the host/port.
If all this doesn't help, set a breakpoint at Util.java line 389 or in the try block before see, what actually is happening and failing.
I having some trouble to connect to my mysql server from my java/scala worker.
Here is the stack trace I got:
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.GeneratedConstructorAccessor25.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.6.0_27]
at java.lang.reflect.Constructor.newInstance(Constructor.java:532) ~[na:1.6.0_27]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.6.0_27]
at java.lang.reflect.Constructor.newInstance(Constructor.java:532) ~[na:1.6.0_27]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at java.sql.DriverManager.getConnection(DriverManager.java:620) ~[na:1.6.0_27]
at java.sql.DriverManager.getConnection(DriverManager.java:200) ~[na:1.6.0_27]
at listen$IndexTransactionWorkerImpl.run(listen.scala:38) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at net.greghaines.jesque.worker.WorkerImpl.execute(WorkerImpl.java:630) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at net.greghaines.jesque.worker.WorkerImpl.process(WorkerImpl.java:600) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at net.greghaines.jesque.worker.WorkerImpl.poll(WorkerImpl.java:491) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at net.greghaines.jesque.worker.WorkerImpl.run(WorkerImpl.java:230) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at java.lang.Thread.run(Thread.java:679) [na:1.6.0_27]
Caused by: java.net.UnknownHostException: mysql-vip
at java.net.InetAddress.getAllByName0(InetAddress.java:1229) ~[na:1.6.0_27]
at java.net.InetAddress.getAllByName(InetAddress.java:1156) ~[na:1.6.0_27]
at java.net.InetAddress.getAllByName(InetAddress.java:1092) ~[na:1.6.0_27]
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:249) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
... 29 common frames omitted
It works fine until a certain point, the worker is unable to resolve the host. If I restart the worker, it is working again.
Important thing: I am able to ping the host from the machine!
I tried to use ipv4 instead with Djava.net.preferIPv4Stack=true but I got the same error with the ipv4 stack.
I don't have any clue so far! Thanks for your help guys!
There can be multiple reasons for this Well it might happen if you do not manage your connection pool properly. in the sense if you are maintaining a connection pool yourself (or say using apache dhcp or something), then either you have too many connections open that everything gets blocked or not managing the resources well.
Another reason can be this: (It happened with us over a month back). When too many long queries were being executed at once. We did some optimizations on procedure side and things started working (By disabling read locks).
I am using Squirrel to connect to a MySQL instance being hosted on CloudBees. I downloaded what I believe is the correct JDBC driver, and installed it to Squirrel's lib directory at:
~/squirrel-sql-3.4.0/lib/mysql-connector-java-5.1.25-bin.jar
I then created a new DB alias (inside Squirrel) with the following properties:
Name: my_db
Driver: MySQL Driver
URL: jdbc:mysql://my-cloudbees-s3-instance.com:3306/my_db
User Name: my_db_user
Password: *******
When I try to connect to the DB, I get the following stack trace/error from Squirrel's built-in console:
java.util.concurrent.ExecutionException: java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'my_db_user'#'%' to database 'my_db'
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:232)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.awaitConnection(OpenConnectionCommand.java:132)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$100(OpenConnectionCommand.java:45)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$2.run(OpenConnectionCommand.java:115)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
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:662)
Caused by: java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'my_db_user'#'%' to database 'my_db'
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:171)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$000(OpenConnectionCommand.java:45)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$1.run(OpenConnectionCommand.java:104)
... 6 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'my_db_user'#'%' to database 'my_db'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:927)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1709)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1252)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
at net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(SQLDriverManager.java:133)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:167)
... 8 more
Is this an issue with:
Squirrel, or how I've configured it; or
The database/server (not properly configured, etc.); or
My connection properties; or
The MySQL/JDBC driver (wrong type, etc.); or
Something else?
It says "Access is denied" but I've check and rechecked my login credentials and they seem to be perfectly valid. Thanks in advance!
Important Update: I just downloaded and installed MySQL Workbench, created a new Stored Connection with the exact same info, and still getting the same error message:
Failed to Connect to MySQL at my-cloudbees-s3-instance.com:3306 with user my_db_user. Access denied for user 'my_db_user'#'%' to database 'my_db'.
To me, this indicates the MySQL server has been configured incorrectly, and rules out Squirrel, my connection properties, and the JDBC driver I installed for Squirrel...yes?!?
My java prog is compiling and executing fine with
mysqlCon = (Connection) DriverManager.getConnection("jdbc:mysql://10.129.70.44:3306/test", "root", "root");
but when I type
mysqlCon = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
it is faling
giving following error:
Exception in thread "main" 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(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:222)
at just.main(just.java:17)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:235)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305)
... 15 more
Again, when I do $mysql -hlocalhost -u root -p in Ubuntu 12.04 terminal its connecting to mysql>
but when I am typing $telnet localhost 3306 I am getting the following error:
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
You need to grant all to root from localhost.
GRANT ALL ON *.* TO 'root'#'localhost'
Did you try 127.0.0.1 instead of Localhost?
On the side note:
If you have any mysql client, then try there first. Probably you can try to connect from command prompt first. If it works, then you can use that.