Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

database connectivity error

 
Deepanshu Saxena
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
IBM DB2 Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raj Java Raj
Greenhorn
Posts: 5
IBM DB2 Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic