using DriverManager.getConnection.

Share

Hello all,

I have a question in using DriverManager.getConnection.

Its parameter is a string containing the url of the data source.

Im using a SQL database, and i defined the url of the datasource as:

radius.dsrc="jdbc:odbc:@192.168.1.182:AdslAccess5-1-07"

where AdslAccess5-1-07 is the name of the data source and

192.168.1.182 is the IP of the host on which the database resides.

Is the way i defined the url of the database corect or no? Because it constantly gives me an error that data source not found and no default driver has been specified.

Thanx alot

      Gehan Mustafa

Is it MS Access  or SQL Server ?


Ahmed Hashim

Software Engineer

hashimblog/

Its SQL Server, thanks a lot for the quick reply

So, you should not use jdbc:odbc:blabla

Instead, use the MS SQL Server JDBC Driver or jTDS OpenSource implementation.

The use this URL to connect to the database

 

con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://192.168.1.182:1433;databaseName=AdslAccess5-1-07;selectMethod=cursor",
"userName", "password");


There is a good How To in MS website 


Ahmed Hashim

Software Engineer

hashimblog/

In this case i will have to download the MS SQL Driver from the link you put in your previous mail.

However when we use before DrverManager.GetConnection the function :

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Of course the string given as the input would be changed, what will i write instead?

Thanx alot

Use

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")

There is a good sample here 


Ahmed Hashim

Software Engineer

hashimblog/

 
Gehan, I think that there is something here that I'm not comfortable with, which is the server IP address.

AFAIK If you are using ODBC datasource I think that you configure the server IP in the ODBC administration control panel not in the JDBC URL (as I think). and the ODBC automatically bridges your connection to the pre-configured server.

So try to remove the IP section from the connection URL and configure your ODBC datasource to use the correct server IP.

And remember that you need to preload the JdbcOdbcDriver before trying to obtain a connection.


Michael's eHome :: Free Coder ...

Thanks alot for your help, ill try it now.