• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

MYSQL Connection error Plz help

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
ice is for people that are not already cool. Chill with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic