Solved

DataSource????

Posted on 2002-06-17
20
538 Views
Last Modified: 2010-03-31
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...

0
Comment
Question by:rdy1437
  • 10
  • 6
  • 3
  • +1
20 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 7085408
You allways will need a driver (external to your application or the default jdbcodbc driver).
0
 
LVL 3

Expert Comment

by:daitt
ID: 7086225
Something like this:
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:dsn");
0
 
LVL 92

Expert Comment

by:objects
ID: 7086671
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.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 3

Expert Comment

by:daitt
ID: 7086847
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 7086932
> are usually the native ODBC drivers come with your DBMS.

Or pure JDBC drivers.
0
 

Author Comment

by:rdy1437
ID: 7086965
another thing, what's the difference of RMI and Reflection?
0
 
LVL 92

Expert Comment

by:objects
ID: 7087002
RMI is used for calling classes in other JVM's.
Reflection is for creating and calling instances at runtime.
0
 
LVL 92

Expert Comment

by:objects
ID: 7087025
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.
0
 

Author Comment

by:rdy1437
ID: 7087031
Can u give more details about reflection(probably some code)?
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 7087074
Class cls = Class.forName("java.lang.Integer");
Method tostring = cls.getMethod("toString", null);
Object s = cls.newInstance();
String s = (String) tostring.invoke(s, null);

0
 

Author Comment

by:rdy1437
ID: 7087082
Can u give more details about reflection(probably some code)?
0
 
LVL 92

Expert Comment

by:objects
ID: 7087109
0
 
LVL 3

Expert Comment

by:daitt
ID: 7087485
>> 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.
0
 
LVL 92

Expert Comment

by:objects
ID: 7091153
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
0
 
LVL 3

Expert Comment

by:daitt
ID: 7091291
and only type 1 uses datasource
0
 
LVL 92

Expert Comment

by:objects
ID: 7091310
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.
0
 
LVL 3

Expert Comment

by:daitt
ID: 7091457
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 7091483
> 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.
0
 
LVL 3

Expert Comment

by:daitt
ID: 7091515
my bad .. I thought it was DSN which is ODBC.
0
 
LVL 92

Expert Comment

by:objects
ID: 7091531
:-)  No worries.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spring Framework HTTPSession management 1 33
Oracle SQL syntax check  without executing 6 50
servlet example 11 40
Java Restore security prompts not working 10 9
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question