lilyyan
asked on
jsp mysql, change db connection form localhost to remote IP address
Hello experts
I'm using mysql and jsp. when I connect to the db :
java.sql.DriverManager.get Connection ("jdbc:mys ql://local host/mypro ject","use rName", "userPassword");
the above statement will work.
but , java.sql.DriverManager.get Connection ("jdbc:mys ql://myIPa ddress:330 6/myprojec t","userNa me", "userPassword");
it won't work.
May you give me suggestion about this?
Thank you for your help.
I'm using mysql and jsp. when I connect to the db :
java.sql.DriverManager.get
the above statement will work.
but , java.sql.DriverManager.get
it won't work.
May you give me suggestion about this?
Thank you for your help.
Have you tried without the port number
ASKER
yeah, i've tried without the port number.
Also try:
java.sql.DriverManager.get Connection ("jdbc:mys ql://127.0 .0.1:3306/ myproject" ,"userName ", "userPassword");
and check that you don't have any firewalls that could affect this connection
java.sql.DriverManager.get
and check that you don't have any firewalls that could affect this connection
What driver are you using, the Connector/J one?
ASKER
127.0.0.1:3306 is working
And what is your exception error...
ASKER
The connetcor driver is : mysql-connector-java-3.1.7 -bin.jar
ASKER
The null point exception thrown out from sqlRst.close();
>> The null point exception thrown out from sqlRst.close();
You're getting nothing back from the connection.
>> 127.0.0.1:3306 is working
This means that the code is correct. 127.0.0.1:3306 resolves to localhost for mysql which shows that your code is correct and the error is caused by somehting else. Either the IP is incorrect or you have a network issue such as a proxy or firewall which has closed the access to that port.
You're getting nothing back from the connection.
>> 127.0.0.1:3306 is working
This means that the code is correct. 127.0.0.1:3306 resolves to localhost for mysql which shows that your code is correct and the error is caused by somehting else. Either the IP is incorrect or you have a network issue such as a proxy or firewall which has closed the access to that port.
PS you should always do a null check on the ResultSet object before you call close. Same goes for statement and connection.
e.g.
if ( sqlRst!=null ){
sqlRst.close() ;
}
e.g.
if ( sqlRst!=null ){
sqlRst.close() ;
}
ASKER
Thanks for your reply.
From antivirus and windows firewall which are installed in my pc, I did't find port 3306 is blocked.
Coud it be some issue related to the grant Privilege? But the user name I currrently used is root.
From antivirus and windows firewall which are installed in my pc, I did't find port 3306 is blocked.
Coud it be some issue related to the grant Privilege? But the user name I currrently used is root.
>>Coud it be some issue related to the grant Privilege? But the user name I currrently used is root.
I doubt it as if it were access, it would not work at all if it were and you can get it to work on "locahost" and "127.0.0.1". How are you getting your IP address, are you using "ipconfig"?
It looks like an annoying network issue. Are you on a home machine or a work one, i.e. are you using a LAN?
I doubt it as if it were access, it would not work at all if it were and you can get it to work on "locahost" and "127.0.0.1". How are you getting your IP address, are you using "ipconfig"?
It looks like an annoying network issue. Are you on a home machine or a work one, i.e. are you using a LAN?
ASKER
The IP address is correct. I'm using it in tomcat. Also I checked with ipconfig in dos command line. It's same IP.
I'm using a pc within a LAN.
I'm using a pc within a LAN.
>>I'm using a pc within a LAN.
Then you might have issues with a proxy server and NAT. Can you ping that address?
Then you might have issues with a proxy server and NAT. Can you ping that address?
ASKER
Yeah, I just did a test.
ping myipaddress
I got something like : Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
ping myipaddress
I got something like : Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
So the address is a viable one but for some reason the datbase is not responding. Weird. Check your hosts file to see that the IP is not being mapped to somewhere else.
What are you trying to do with this db?
What are you trying to do with this db?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks all for your replies,
Currently my db only have one user and the user name is root.
>>mysql> grant all privileges on myproject.* TO 'username'@'%' identified by 'userpassword'; //assuming test is your database name.
>>mysql> flush privileges;
I used above command, and added another user. Now everything works fine. But somehow the program runs much slower than before.
Do you have any suggestion about this ?
Thanks for your help.
Currently my db only have one user and the user name is root.
>>mysql> grant all privileges on myproject.* TO 'username'@'%' identified by 'userpassword'; //assuming test is your database name.
>>mysql> flush privileges;
I used above command, and added another user. Now everything works fine. But somehow the program runs much slower than before.
Do you have any suggestion about this ?
Thanks for your help.
ASKER
>>either you add one more record in the table for the same user but with the host as "%"
The user root only has localhost access. If I changed it to %, will this be a good idea for program speed and safety?
Thanks for your reply.
The user root only has localhost access. If I changed it to %, will this be a good idea for program speed and safety?
Thanks for your reply.
ASKER
I am not sure the reason. Now , the speed is just as fast as before.
And it seems that I don't need add port 3306 in the db connection statement.
And it seems that I don't need add port 3306 in the db connection statement.
Performance will not go down due to the fact that you gave more access. It will go down because now your db can be accessed from anywhere and hence, more traffic and slow.
Yea.. You dont need the port.
>> The user root only has localhost access. If I changed it to %, will this be a good idea for program speed and safety?
Well.. of course by giving access from anywhere certainly reduces your safety. If you want to give access only from let say "http://lilyyan.com", use the following:
grant all on myproject.* to 'username'@'lilyyan.com' identified by 'userpassword'.
But the safe way is to creata another user with the above rights to access your database and not use the superuser i.e. root.
Yea.. You dont need the port.
>> The user root only has localhost access. If I changed it to %, will this be a good idea for program speed and safety?
Well.. of course by giving access from anywhere certainly reduces your safety. If you want to give access only from let say "http://lilyyan.com", use the following:
grant all on myproject.* to 'username'@'lilyyan.com' identified by 'userpassword'.
But the safe way is to creata another user with the above rights to access your database and not use the superuser i.e. root.
ASKER
Hi kupra1 ,
Can you help me check the question I posted under mysql topic. Thanks a lot .
Can you help me check the question I posted under mysql topic. Thanks a lot .
I am going there. Hold on.