0

I have been having issues specifying the path (I have two files: comments.frm and db.opt in the following folder: C:\xampp\mysql\data\feedback)... I am using XAMPP and mySQL. I am not sure why I am having an error? Please, take a look this part of my code:

public void readDataBase() throws Exception {
   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
    connect = DriverManager
         .getConnection("jdbc:mysql://localhost//feedback"
              + "user=root&password=1234");

PS: My password for localhost is 12345678

1
  • The connection string will be wrong since you are concatenating user to feedback: jdbc:mysql://localhost//feedbackuser=root&password=1234. Commented Apr 4, 2013 at 8:06

6 Answers 6

2

You should try

DriverManager.getConnection("jdbc:mysql://localhost/feedback", "root", "1234");
Sign up to request clarification or add additional context in comments.

Comments

2

For better clarity you can use the other overloaded method while getting connection.

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://<db_ip>/<db_name>", 
    "<username>", "<pwd>");

Comments

2

Try

 connect = DriverManager
     .getConnection("jdbc:mysql://localhost/feedback?user=root&password=1234")

(you forgot about the question mark after "feedback")

Comments

1

Many answers but everyone forgot the port of the database.

If you use mysql then try 3306 as db port.
http://www.petefreitag.com/articles/jdbc_urls/ - list of jdbc urls (Examples)

try 
{ 
    conn = DriverManager.getConnection("jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName, user, passwd); 
} 
catch(SQLException sqle) 
{ 
    System.out.println("Connection fails: " + sqle.getMessage()); 
}

Comments

1

I think you need to use this:

DriverManager.getConnection("jdbc:mysql://localhost:3306/feedback", "root", "1234");

I check my old project and find that I don't use double slash here /feedback.

also you can specify encoding like this :

 DriverManager.getConnection("jdbc:mysql://localhost:3306/feedback?characterEncoding=UTF-8&characterEncoding=Cp1251", "root", "1234");

and also one more advice. Don't use hard code. Get url, password and user name from property files.

Comments

1

Try this hope it can help you!!!

Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/feedback?"+"user=root&password=1234");

also see the URL Mistakes like:

jdbc:mysql://localhost//feedback?

// after localhost... check and try my code...

.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.