This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes database connectivity error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "database connectivity error" Watch "database connectivity error" New topic
Author

database connectivity error

Deepanshu Saxena
Greenhorn

Joined: May 10, 2012
Posts: 5
Hi everyone i am getting this error i am trying to connect my application to the mysql databse which is at other system..
I had already grant permission to the user using this command :

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.60.185' IDENTIFIED BY 'root' WITH GRANT OPTION;

and i have written code like this..
public class Checkdatabase {

Connection con=null;
Statement stmt=null;
ResultSet rs=null;

public static void main(String[] args) throws ClassNotFoundException, SQLException {
Checkdatabase d =new Checkdatabase();
int a=d.authentication("deep","deep");
System.out.println("the value of a is" + a);
//d.delete("deep");
}

public Checkdatabase() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://192.168.60.184:3306/mysql","root","abcd");
stmt=con.createStatement();

}

public int authentication(String username,String sess) throws ClassNotFoundException, SQLException
{
int ret=0;
rs=stmt.executeQuery("select * from temp2 where name='" + username +"' and sessionid='" +sess +"'");
if(rs.next())
ret=1;
else
ret=0;
return ret;
}

still i am getting this error ;

java.sql.SQLException: Access denied for user 'root'@'192.168.60.185' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3996)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2137)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776)
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:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:200)
at a.Checkdatabase.<init>(Checkdatabase.java:27)
at Check.processRequest(Check.java:39)
at Check.doPost(Check.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:679)
Raj Java Raj
Greenhorn

Joined: May 14, 2012
Posts: 5

Hi , Deepanshu

Follow below Simple Step for database connectivity.

1.Load Driver
2.Establishing Connection
3.Executing Statements
4.Getting Results
5.Closing Database Connection


------------------------
Raj.
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

This question is not related to JSP but with JDBC. Please read CarefullyChooseOneForum and select proper forum before posting your question.


Coming to your question. Just make sure that your user, id, password, db schema name, etc are all correct. Try to access the DB through command line with the same credentials.

Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Raj Java Raj
Greenhorn

Joined: May 14, 2012
Posts: 5

I agree with Palak!!

Deepanshu is getting error with database url , i think code base given by me may help him to sort out issue.

-------
Raj.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: database connectivity error
 
Similar Threads
mysql connection using eclipse (ubuntu)
I can not for the life of me figure out what is causing this
Using PreparedStatement
Error while using DriverManager to connect to MySQL DB.
MySQLSyntaxErrorException