JDBC Connection issues with MySQL - java

I've been looking over StackOverflow for the last two days for similar problems and have found many people with the same issue, however, nothing suggested has worked for me so I figured I would post my exact question here in case I'm missing something obvious. I've noticed the connection refused causation, however, I know exactly what my username and password is as well as the dbname, so I know it's not an authentication problem.
After much frustration, I have found a class that simply checks the version of MySQL running on my machine. I am running MySQL using XAMPP as well. However, no matter what I try to do, I get the following error:
Apr 26, 2014 7:29:37 PM Version main
SEVERE: 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.
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:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2539)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2321)
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(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at Version.main(Version.java:23)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:241)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 15 more
And here is my Version class:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Version {
public static void main(String[] args) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/dbname";
String user = "username";
String password = "password";
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
rs = st.executeQuery("SELECT VERSION()");
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Version.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Version.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
}

I was able to get this working.
I had to reinstall XAMPP and recreate the Database from scratch from the Exported SQL.
You have no idea how annoyed I was to do this. Lots of wasted time. Thanks for the help.

On ubuntu i work with MySQL and tried to edit a file with terminal
sudo nano /etc/mysql/my.cnf
find the line that contains:
bind-address
just edit this line
bind-address = 0.0.0.0
save the file and restart mysql with
sudo service mysql restart and try again
it worked for me, good luck!

You missed some code pal! try adding Class.forName(com.mysql.jdbc.Driver); in your try catch block. hope it helps

Related

Unable to get Oracle database connection,oracle.net.ns.NetException: Undefined Error

I wanted to connect to an Oracle database using JDBC.
I installed ojdbc6.jar properly and wrote this code.
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnect {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.OracleDriver");
String url = "jdbc:oracle:thin:#192.168.127.129:1521:helowin";
String id = "msa_checkin";
String pass = "msa0526";
Connection con = DriverManager.getConnection(url, id, pass);
if(con != null)
System.out.println("Oracle success");
else
System.out.println("Oracle failed");
}
catch(Exception e) {
System.out.println("Error");
e.printStackTrace();
}
}
}
But the output looks like this.
Error
java.sql.SQLException: Undefined Error
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(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.kinth.DBConnect.main(DBConnect.java:14)
Caused by: oracle.net.ns.NetException: Undefined Error
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:385)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 7 more
I search for similar questions,but it doesn't solve my problem.
Unable to get Oracle database connection, should I format my computer?
No problem with Navicat.
Navicat Image
I tried using oracle6.jar and Oracle14.jar but neither worked.
Can you follow the instructions on this page and try to get a connection using the latest JDBC drivers?

Connection to Postgres Database failes

I'm trying for the first time to JDBC to connect to a local database (Postgres) but I can't seem to actually made the connection. This is my code:
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
public class JDBCExample {
public static void main(String[] argv) {
System.out.println("-------- PostgreSQL "
+ "JDBC Connection Testing ------------");
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your PostgreSQL JDBC Driver? "
+ "Include in your library path!");
e.printStackTrace();
return;
}
System.out.println("PostgreSQL JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/training", "iam47662285",
"MY56KZDZ");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
}
}
And this is the error that appears when i try to execute it:
-------- PostgreSQL JDBC Connection Testing ------------
PostgreSQL JDBC Driver Registered!
Connection Failed! Check output console
Nov 02, 2017 4:36:52 PM org.postgresql.Driver connect
SEVERE: Connection error:
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "iam47662285"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:438)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:222)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:450)
at org.postgresql.Driver.connect(Driver.java:252)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at UF2.Pruebas.BDR_BDOO.JDBCExample.main(JDBCExample.java:33)
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "iam47662285"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:438)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:222)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:450)
at org.postgresql.Driver.connect(Driver.java:252)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at UF2.Pruebas.BDR_BDOO.JDBCExample.main(JDBCExample.java:33)
I use Fedora, but i don't know if that's relevant. Anyone have any idea of why is this happening?
Your username/password is incorrect in the following code:
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/training", "iam47662285",
"MY56KZDZ");
Manually log in to psql and verify what the correct username/password is. If necessary ALTER USER "xxxx" WITH PASSWORD ''; to a new one that you'll remember.
Also hardcoding login details is a very bad idea.

access to database remotely-NESTED EXCEPTION

I want to make a connection to the remote database ssh, in my java program, so I write a java code for this, I can ssh to the database server from my code but I can't access to the database, this is my out put which contains the error :
(this link is my previous question link ,which is related to this question)
hi
identity added
session created.
session connected.....
shell channel connected....
connecting to database ...
db Method...
try-catch
Connecting to database...
DB_URL : jdbc:mysql://localhost:3366/DBNAME
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
STACKTRACE:
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:573)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1044)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2748)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Main.connectToDB(Main.java:78)
at Main.main(Main.java:49)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
STACKTRACE:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
STACKTRACE:
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:573)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1044)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2748)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Main.connectToDB(Main.java:78)
at Main.main(Main.java:49)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:641)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1044)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2748)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Main.connectToDB(Main.java:78)
at Main.main(Main.java:49)
** END NESTED EXCEPTION **
Last packet sent to the server was 1 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2820)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Main.connectToDB(Main.java:78)
at Main.main(Main.java:49)
Goodbye!
done
I run this code
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class Main {
public static void main(String[] arg) {
try {
System.out.println("hi");
JSch jsch = new JSch();
String user = "***";
String host = "**.**.***.***";
int port = 22;
String privateKey = "id_rs";
jsch.addIdentity(privateKey);
System.out.println("identity added ");
Session session = jsch.getSession(user, host, port);
System.out.println("session created.");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
session.setPortForwardingL( 3366, host, 3306) ;
System.out.println("session connected.....");
Channel channel = session.openChannel("sftp");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect();
System.out.println("shell channel connected....");
System.err.println("connecting to database ...");
connectToDB();
System.out.println("done");
} catch (Exception e) {
System.err.println(e);
}
}
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static String databaseName ="DBNAME";
static int lport = 3366;
static final String DB_URL = "jdbc:mysql://localhost:"+lport+"/"+databaseName;
static final String USER = "***";
static final String PASS = "***";
public static void connectToDB() {
System.out.println("db Method...");
Connection conn = null;
Statement stmt = null;
try{
System.out.println("try-catch");
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...");
System.err.println("DB_URL : "+DB_URL);
System.err.println(USER+":"+PASS+";");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("hey!");
stmt = conn.createStatement();
String sql;
sql="SELECT * from Customer_Classes ; ";
ResultSet rs = stmt.executeQuery(sql);
try (BufferedWriter bw = new BufferedWriter(new FileWriter("a.txt"))) {
while(rs.next()){
String name = rs.getString("ID");
bw.write(name);
bw.newLine();
System.out.println(" name: " + name);
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
System.err.println("unable to close statement");
}
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
System.err.println("unable to close connection");
se.printStackTrace();
}
}
System.out.println("Goodbye!");
}
}
I define a user in remote server with all privilages
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'IP' IDENTIFIED BY 'PASSWORD';
and add my Ip to bind-address in my.cnf (in DBserver)
what this errors means? and how can I fix it?
When connecting through portforwarding, the database will not see your original IP address, but the local one (localhost). So your grant should be GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'localhost' IDENTIFIED BY 'PASSWORD';
Mysql's bind-address parameter is for configuring the server IP, not the client IP. You should leave that setting (unless you otherwise need it) at its default, since you will be connecting from localhost anyway.
If Channel channel = session.openChannel("sftp");does what it seems to (i.e. connect you to the SFTP subsystem), sshd will probably not let you connect elsewhere. You should use Channel channel = session.openChannel("shell");
Check the server log.

Connecting MSAccess database with java webapplication

I am trying to connect Msaccess database with my java webapplication using the following code:
import java.sql.*;
public class connection {
public static void main(String[] args) {
try {
// Load MS accces driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("loaded");
String url = "jdbc:odbc:OnboardingTT";
System.out.println("assigned");
// specify url, username, pasword - make sure these are valid
Connection conn = DriverManager.getConnection(url,"","");
System.out.println("Connection Succesfull");
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}}}
But connection is not established. and the error is
loaded
assigned
Got an exception!
null
java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.initialize(Unknown Source) at
sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source) at
java.sql.DriverManager.getConnection(Unknown Source) at
java.sql.DriverManager.getConnection(Unknown Source) at
connect.connection.main(connection.java:18)
I also tried with
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ="+ "C:\\OnboardingTT.mdb";
Is this code correct or i have to do any changes in this please answer my question
Looks like something went wrong with the DB connection, maybe the DB is not online, maybe the user or the password are incorrect...
Please provide more info to help us to help you.
;-)

Can't Connect to Database from Java program

I installed MySQL database & JDBC. I created a database called feedback through MySQL command line client, and I want to access that database through a java program.
Here is the commands I used on MySQL command line client create the database.
create database feedback;
use feedback;
CREATE USER sqluser IDENTIFIED BY 'sqluserpw';
grant usage on *.* to sqluser#localhost identified by 'sqluserpw';
grant all privileges on feedback.* to sqluser#localhost;
CREATE TABLE COMMENTS (id INT NOT NULL AUTO_INCREMENT,
MYUSER VARCHAR(30) NOT NULL);
INSERT INTO COMMENTS values (default, 'lars');
Then, the code in Java:
package de.vogella.mysql.first;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import javax.swing.JOptionPane;
public class MYSQLACCESS {
private Connection connect = null;
private Statement statement = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
public void readDataBase() throws Exception {
JOptionPane.showMessageDialog(null, "Before try" );
try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
JOptionPane.showMessageDialog(null, "1" );
connect = DriverManager.getConnection("jdbc:mysql://localhost/feedback?"
+ "user=sqluser&password=sqluserpw");
// Statements allow to issue SQL queries to the database
statement = connect.createStatement();
// Result set get the result of the SQL query
resultSet = statement.executeQuery("select * from FEEDBACK.COMMENTS");
// writeResultSet(resultSet);
String my_user = resultSet.getString("MYUSER");
System.out.println(my_user);
JOptionPane.showMessageDialog(null, my_user );
} catch (Exception e) {
throw e;
}
}
}
The Main Class:
package de.vogella.mysql.first;
import de.vogella.mysql.first.MYSQLACCESS;
public class Main {
public static void main(String[] args) throws Exception {
MYSQLACCESS first_access = new MYSQLACCESS();
first_access.readDataBase();
}
}
However, I get the following exception:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Access denied for user 'sqluser'#'localhost' to database 'feedback'
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: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:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2526)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311)
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(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:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at de.vogella.mysql.first.MYSQLACCESS.readDataBase(MYSQLACCESS.java:30)
at de.vogella.mysql.first.Main.main(Main.java:7)
I am following the tutorial in the following link
Any help?
The user sqluser does not have the privileges to access database feedback on the localhost.
Use the mysql command line tool and grant the privileges to the user.
Do not forget to flush privileges
usually when having this exception:
Access denied for user 'sqluser'#'localhost' to database 'feedback'
means that this user don't have enough privileges to access the Database, what I would suggest you to do is to go to your SQL shell and write this command:
show grants;
it would show you which users has access to the Database and with their level of privilege
if this user don't seem to have the necessary privilege to access the DB you can grant it to him by writing this query in your SQL Shell
GRANT ALL PRIVILEGES ON *.* TO 'sqluser'#'localhost' WITH GRANT OPTION;
Good Luck;

Categories