Link to home
Start Free TrialLog in
Avatar of rdy1437
rdy1437

asked on

DataSource????

Hi guys!!!
 
I have a question regarding the datasource in jdbc. If i used datasource to connect to database(mysql) should i still need a driver?Can u give me some code on how to conenction using datasource??

thanks...

Avatar of Ovi
Ovi

You allways will need a driver (external to your application or the default jdbcodbc driver).
Something like this:
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:dsn");
Avatar of Mick Barry
DataSource just provides an alternate interface for your application to use to connect with the database. Behind the scenes you'll still need some form of connection to your database which will most probably be a JDBC driver.
I think ODBC is an API that provides a common programming interface to communicate with different DBMSs. JDBCODBC is a bridge that maps JDBC API to ODBC API (and it works the same way with any DBMS). So the drivers behind the scenes are usually the native ODBC drivers come with your DBMS.
> are usually the native ODBC drivers come with your DBMS.

Or pure JDBC drivers.
Avatar of rdy1437

ASKER

another thing, what's the difference of RMI and Reflection?
RMI is used for calling classes in other JVM's.
Reflection is for creating and calling instances at runtime.
RMI allows you to call methods of objects running in a different JVM.

Reflection allows you to obtain information about a class and it's members, and to manipulate objects at runtime.
Avatar of rdy1437

ASKER

Can u give more details about reflection(probably some code)?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rdy1437

ASKER

Can u give more details about reflection(probably some code)?
>> are usually the native ODBC drivers come with your DBMS.

> Or pure JDBC drivers.

No, it cannot be a JDBC driver, because basically JDBC API is different from ODBC API. A driver for jdbcodbc bridge must provide ODBC interface, not JDBC. Of course, that might happen if somebody writes a JDBC driver that works for every DBMS and claim that it's a bridge (but I guess nobody's gonna do so)

rdy1437: I was very supprised when I saw the accepted answer. It's completely not related to your original question.
JDBC drivers come in 4 types, only type 1 uses ODBC:

Type 1: JDBC-ODBC Bridge
Type 2: Native-API/partly Java driver
Type 3: Net-protocol/all-Java driver
Type 4: Native-protocol/all-Java driver
and only type 1 uses datasource
No DataSource can be used with all types, I'm currently using it in a project with a type 3 driver. And DataSource can also be used with other technologies such as LDAP.
I think datasource is an element of ODBC, so who uses it will interact with ODBC and will be a bridge. Maybe your type 3 driver also supports type 1?
LDAP and any other technologies can use datasource as they wish. They will be able to connect and perform database actions easily without (or with a little) worrying about which DBMS it's working with.
> I think datasource is an element of ODBC

DataSource is a Java interface, while ODBC is a database standard (not directly related to Java at all). So I wouldn't think it is an element of ODBC.

> Maybe your type 3 driver also supports type 1?

No and its an unsigned applet so it can't be.

> LDAP and any other technologies can use datasource as they wish.

This implies that LDAP uses ODBC which is not the case.

> They will be able to connect and perform database actions
> easily without (or with a little) worrying about which
> DBMS it's working with.

LDAP is not for connecting to DBMS's.
my bad .. I thought it was DSN which is ODBC.
:-)  No worries.