PDA

View Full Version : Java connectivity to remote sql database


jerry
01-05-2009, 04:45
I have a web application in java. I am trying to connect to database on another machine. I am able to connect to local host using url [url="jdbc:mysql://localhost/database_name"/], but it couldn't connect to remote SQL database (5.0). I tried to replace local host with remote server's url, but of no use.
Could someone guide what changes I need to do in code for remote database connectivity.

My sql database is on linux server. I am trying to access it using another either windows or linux machine. My web application is Java and I am using following code foe local connectivity.

<Context path="/InformProject" docBase="InformProject">

<Resource name="jdbc/informDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" factory="org.apache.commons.dbcp.BasicDataSourceFactory"
username="userid" password="userpass" driverClassName="com.mysql.jdbc.Driver"
testWhileIdle="true" timeBetweenEvictionRunsMillis="10000" minEvictableIdleTimeMillis = "60000"
validationQuery="SELECT 1 = 1" logAbandoned="true"
url="jdbc:mysql://localhost/database_name"/>

<Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99"
dataSourceName="jdbc/informDB" localDataSource="true" digest="MD5"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name"/>


</Context>

Thanks,

Kees de Kooter
01-05-2009, 08:21
1. is the name of the remote host properly resolved?
2. is the user allowed to connect to this remote database - check the user permissions

And next time please post the relevant stacktraces.

jerry
01-05-2009, 14:03
1. Remote host name is something (host_name.xyz.edu) and it is correct. I am using url for remote is url="jdbc:mysql://host_name.xyz.edu/database_name". I have tried to put the port number too, which is the default port number for sql (3306), but that didn't work either.

2. I have administrative permissions to access to sql database.

Kees de Kooter
01-05-2009, 18:30
Did you check the firewall configuration on the remote machine?

Can you access the remote database with the mysql tools?

kjkoster
04-05-2009, 08:42
Dear Jerry,

Please post the stack traces you are getting. These stack traces usually allow others to spot the error quickly.

Also, note that MySQL does not accept remote connections when there are no users configured to be able to connect remotely.

Kees Jan

Barry
22-05-2009, 14:35
Jerry,

Did you manage to fix this issue?
Have you tried pinging the hostname or doing a telnet hostname 3306 and seeing if that works?

jerry
22-05-2009, 16:29
Barry,

Yes I was able to fix the problem. As was suggested in earlier message, I checked MySQL settings and I found, SQL wasn't set for remote connectivity.

Thanks

Barry
23-05-2009, 13:59
Ah good to hear you got it fixed :)

helicop
28-06-2009, 18:27
I understand how to construct the sql string now, but now, Im not sure what the parts of this statement are:

ResultSet myRS = RS.resultSetsql.toString, connDB;

Is ResultSet the name of the java class? Or, is that myRS?

Barry
28-06-2009, 19:22
I understand how to construct the sql string now, but now, Im not sure what the parts of this statement are:

ResultSet myRS = RS.resultSetsql.toString, connDB;

Is ResultSet the name of the java class? Or, is that myRS?

Genius question of the week award in...3..2..1