help me out here

when i wana use the java jdbc to connect mysql database, i cann't understand what does the following means: Class.forName("com.mysql.jdbc.Driver").newInstance(); very appreciate your help
[209 byte] By [lostagaina] at [2007-11-26 12:40:29]
# 1

A JDBC connection requires a driver that is specific to your DB. The line you gave simply creates a new DB driver for a MySQL DB.

There's no need for the .newInstance() part. Simply loading the class with the Class.forName() does what you need done.

See this page for some basic intro info on JDBC.

http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html

Hope this helps.

codebooka at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 2
I helped you out. Are you gonna dish out some of those shiny Duke Dollars you promised?
codebooka at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 3
> I helped you out. Are you gonna dish out some of> those shiny Duke Dollars you promised?Hasn't happened yet so probably not. But there's a first time for everything.
cotton.ma at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 4

I take extra time to earn some Duke Dollars in the hopes that when I post a question, people will give me a little help since I've been helpful to the community. However, when people offer 10 Dukes, get the answer they asked for, and still don't give out even 1, that fouls up the whole system. Oh well, not everybody can be expected to be nice.

codebooka at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 5
The "Class.forName()" stuff is what loads the driver
daveknirava at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 6
Already answered in post #2, but no Dukes. In fact, 'lostagin' has at least 3 questions posted, all which have been answered, and no Dukes have been given out for them yet.
codebooka at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 7
> Already answered in post #2, but no Dukes. In fact,> 'lostagin' has at least 3 questions posted, all which> have been answered, and no Dukes have been given out> for them yet.It happens all the time. Theres nothing you can really do about it.
CaptainMorgan08a at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 8
there should be a policy,,, if you dont give the promised duke dollar, then you are tagged to a star of a BIG LIAR, and no should help you
G_Abubakra at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 9
bleh, I've been answering questions here since 1998 and rarely gotten any.Not that I mind much, but if you promise to do something you should do it.
jwentinga at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 10
i'm sorry ,you know i am an new fish here ,not well know about the duke ,all i know is when i assign more duke dollars ,there will be answers, can you tell me all about this ,
lostagaina at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 11
oh god ,you wanna police to punish the innocent one, if you tell me how to assign, than i will do that. and thank you very much..
lostagaina at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 12
> if you tell me how to assign, than i will do> that. and thank you very much..There should be an icon or something like that you can click on.
CaptainMorgan08a at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 13
In the header section of each posting there should be a little Duke icon with a little + sign on it. If you think a posting was helpful, just click on the little icon. It will ask you how many Dukes to reward to the author of the post.
codebooka at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 14

It works fine

Usually when u want to get Connection to a Database

1. Load the driver using Class.forName (Load's the driver into memory and Registers with DriverManager)

2. Get Connection with DriverManager

or we can directly create new instance like

OracleDriver od=new OracleDriver()(Dirctly Crateing the instance)

In you'r case

Class.forName() loads the driver and gives the Class object for that class you'r loading and by calling newInstance() u'r going to getObject for that class .after u'r down cast to u'r class

u'r code may look like//im writing oracle driver here

Object o=Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

OracleDriver or=(OracleDriver)o;

AnjanReddya at 2007-7-7 16:12:03 > top of Java-index,Java Essentials,New To Java...
# 15
does it work ,by the way ,appreciate your help..hope you can always help me out..
lostagaina at 2007-7-7 16:12:05 > top of Java-index,Java Essentials,New To Java...
# 16

> I take extra time to earn some Duke Dollars in the

> hopes that when I post a question, people will give

> me a little help since I've been helpful to the

> community. However, when people offer 10 Dukes, get

> the answer they asked for, and still don't give out

> even 1, that fouls up the whole system. Oh well, not

> everybody can be expected to be nice.

I don't think it a problem since the OP won't get any new dukes before he hands out these dukes.... or?

kajbja at 2007-7-7 16:12:05 > top of Java-index,Java Essentials,New To Java...