This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MYSQL Connection error Plz help

 
prashant parab
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am getting following error while connecting to MYSQL server
Following is my code
import java.sql.*;
public class test{
public test(){
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/ejb?user=root&password=ypbind$12");
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from prashant");
while(rs.next()){
System.out.println("Name "+rs.getString("name"));
}
}catch(Exception ee){
ee.printStackTrace();
}
}
public static void main(String a[]){
new test();
}
}
I am getting following exception. I am able to connect to mysql server using mysql command on command prompt using the same user name and password

java.sql.SQLException: General error: Access denied for user: '@localhost' to da
tabase 'ejb?user=root&password=ypbind$12'
at org.gjt.mm.mysql.MysqlIO.sendCommand(MysqlIO.java)
at org.gjt.mm.mysql.Connection.<init>(Connection.java)
at org.gjt.mm.mysql.Driver.connect(Driver.java)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at test.<init>(test.java:8)
at test.main(test.java:20)

Please help
 
Hartmut Ludwig
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the following:
Put Username and Password and the URL itself in separate Strings.

Now you can use the following:

I'm quite shure that this will work.
 
prashant parab
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for your immediate response. I tried that and atleast now i am not getting that error. Now it is throwing the following exception. Can you kindly tell me reason behind this.

java.sql.SQLException: General Error: null
at org.gjt.mm.mysql.Connection.<init>(Connection.java)
at org.gjt.mm.mysql.Driver.connect(Driver.java)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at test.<init>(test.java:11)
at test.main(test.java:23)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic