0

we are trying to connect to the host using the code shown below:

 Connection con=null;
             try {
                 Class.forName("com.mysql.jdbc.Driver");
                    con=DriverManager.getConnection("jdbc:mysql://sql3.000webhost.com/a17644_cc","chat_cc",                       "pass");          
                 ResultSet rs;
                 if(!con.isClosed())
                 {
                Statement st = con.createStatement();

                  rs= st.executeQuery("SELECT * FROM  user_info");
                 while(rs.next()){
                    t1.append(rs.getString(3));
                 }
                 }
               } catch(Exception e) {
                   t1.setText(e.toString());
                 //e.printStackTrace();
               } finally {
                 try {
                   if(con != null)
                     con.close();
                 }catch (java.sql.SQLException e) {
                    // TODO Auto-generated catch block
                    //e.printStackTrace();
                     t1.setText(e.toString());
                }

we have given internet permission also in the manifest file.

But getting the following error:

java.sql.exception: data source rejected establishment of connection, message from server:"Host '182.71.248.226. is not allowed to connect to this MySQL server"

This is the following details i got: please tell which name we must give in the connection string Domain chitchat.site90.net Username a1740644 Password * Disk Usage 0.14 / 1500.0 MB Bandwidth 100000 MB (100GB) Home Root /home/a1740644 Server Name server19.000webhost.com IP Address 31.170.160.83 Apache ver. 2.2.19 (Unix) PHP version 5.2. MySQL ver. 5.1 Activated On 2012-05-01 02:14 Status Active

kdr
  • 207
  • 1
  • 7
  • 18

4 Answers4

2

That error is telling you that the user does not have rights to connect and select the database. You need to either grant rights to all hosts, or hosts from the specific IP address you are using. To grant to all hosts, you'd have to issue this as an administrative user:

GRANT ALL ON a17644_cc.* TO 'chat_cc'@'%'

or alternatively

GRANT ALL ON a17644_cc.* TO 'chat_cc'@'182.71.248.226'

Assuming that the IP in question is static, and you want to constrain the connection by IP.

gview
  • 14,876
  • 3
  • 46
  • 51
  • con=DriverManager.getConnection("jdbc:mysql:// chitchat.site90.net/a17644_cc","chat_cc", "pass"); Whether this code is proper? – kdr May 08 '12 at 07:02
  • Yes it's using http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/DriverManager.html – gview May 08 '12 at 07:06
  • If you want to do what they mysql jdbc driver suggests: – gview May 08 '12 at 07:10
  • #1044 - Access denied for user 'a17644_cc'@'localhost' to database 'chat_cc' We are getting this error while trying to grant permission – kdr May 08 '12 at 07:12
  • You need to connect to the database in order to grant rights. You can do it with the mysql command line client on the server using mysql -u root -p – gview May 08 '12 at 07:14
1

As pointed out by https://stackoverflow.com/a/1559992/700926 this is probably a security precaution. Check out the accepted answer to that question.

Community
  • 1
  • 1
Lasse Christiansen
  • 10,205
  • 7
  • 50
  • 79
0

What is the port number of MySQL server?Maybe you left it away.

runrioter
  • 533
  • 1
  • 5
  • 11
0

Alternitavely to the answer from gview you can set priviliges in MySQL Workbench.Navigate to Security -> Users and Priviliges.

Nitram76
  • 421
  • 3
  • 13