Complete database newb any help appreciated:

I've written a small program to teach myself new Java concepts and I am ready to implement a DB. I've decided I'd like to start off using a Derby DB and use JDBC to speak with it. Are there any great step-by-step tutorials out there that cover the following main points:

- How to create a Derby DB (I already know exactly how I want the tables structured and stored) - How to retrieve from a Derby DB - How to write new data to the Derby DB - How to use JDBC to speak with the DB

The main interest is that it must be step-by-step, I don't want to copy/paste or import a single file. I already have the JDBC and Derby drivers/jars so I want to write the rest by hand.

Also, do you have to use EJBs to do what I am wanting to do? Like I said I am brand new when it comes to DB, EJB, and JDBC. I just know standard Java, and the only knowledge I have about the rest of this stuff is what I learned getting my SCJA.

Apart from the fact that you only get parts of files, and have to look elsewhere for the whole file, I think the Java� Tutorials offering is good.

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488

posted Nov 26, 2008 10:47:00

0

Thanks, I'll check it out.

What do you mean by "parts of files" though. Do you mean the tutorial is broken up into multiple parts, or that when you retrieve data from the DB that the data is broken up. Like I said, I'm a total newb.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44016

33

posted Nov 26, 2008 11:27:00

0

The whole files are available from links; the tutorial itself tends to show a few lines at a time.

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488

posted Nov 26, 2008 12:31:00

0

Campbell, so far the tutorial seems to be what I am looking for as far as using JDBC to connect to a database and access the information. However, I don't have a database to connect to yet. Do you know of any good tutorials on how to actually make the database to begin with? Preferably a Derby database.

Thanks!

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44016

33

posted Nov 26, 2008 15:50:00

0

I usually use MySQL and I got a book called "Beginning MySQL" by Sheldon and Moes. It may be biased towards MySQL but the middle third is to all intents and purposes a nice general SQL tutorial. It is not expensive, but is unfortunately 3 years old and MySQL has moved on a lot in those 3 years.

You can try googling for an SQL tutorial, but I haven't used them so I feel unable to recommend or warn against any. Sorry I can't be more informative.

You can check out the Netbeans website for some JDBC tutorials. They are quite extensive and frequently use Java Derby as the database. Moreover, Derby comes pre-installed and pre-configured in Netbeans. So, it will save you a lot of headache.

SCJP 1.4 85%

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488

posted Nov 27, 2008 23:44:00

0

Thanks for the replies. I already have Netbeans installed and have used it in the past for making gui easier. I'll have to check out their JDBC tutorials.

So, do you have to use/know SQL to make tables for a database?

I've heard of MySQL before but (here comes the biggest newby question) is MySQL a replacement for Derby, like you use one or the other right?

If so, what are some other database choices and pros/cons of each?

Does JDBC speak with any and all database programs?

Lastly, if you DO need to know/use SQL to make your database does Hibernate abstract that process to make it easier? Basically, does Hibernate hide the SQL knowledge, hide the JDBC knowledge, both, or neither. (I've never really understood what Hibernate is for exactly except that it makes persistence easier supposedly.)

The hardest part of making tables is knowing which tables to make. Do you have a person table with name and address fields, or do you have person name and address tables? That you will need to learn from the tutorials and lots of practice. You will also have to learn about keys, which should be in the tutorials too. MySQL is an open-source database program designed in Sweden; Sun bought the company (MySQL AB) earlier this year. Another popular open-source database is pronounced post-gres (I think) and spelt PostgreSQL.

To get JDBC to work, you need a connector which is usually available from the database supplier; this is a link to details of connectors for MySQL5.0; you want the one called connector/J for Java, and it tells you how to install it. The instructions are comprehensive, but you have to follow them to the letter. Most database programs supply similar connectors.

You can learn on any database; if you have got Derby working use that. Only very slight changes are required to change from one database program to another.

Don't know about Hibernate, I am afraid.

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488

posted Dec 02, 2008 08:26:00

0

Thanks Campbell, that clears a few things up for me.

Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210

posted Dec 04, 2008 19:17:00

0

To understand Hibernat, you need to understand ORM (Object Relational Mapping). Basically, it is a technique of mapping data representation from an object model to an SQL based relational model. So, if you have a list of objects in your application, you can map them into tables in a relational database while maintaining the relationship between the objects. Modern IDEs like NetBeans simplify this to a great extent. Additionally, routine tasks like connection establishment, exception handling, configuration, etc. are taken care of. Some of the examples of ORM tools are Hibernate and TopLink.

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488

posted Dec 05, 2008 08:04:00

0

I appreciate the info, thanks.

"Modern IDEs like NetBeans simplify this to a great extent." Can I also assume that an IDE like RAD or RSA also does this for you?

The biggest problem I am having is figuring out where to start. I know J2SE fairly well and I am trying to delve into the world of J2EE AND learn more about DB stuff. There is just so much info out there and it seems each thing I read up on takes me to more technology I don't know. I need the basics, really. I think Hibernate is out of my league for the time being. I am to novice to even understand the problem it is designed to solve.

Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210

posted Dec 07, 2008 00:47:00

0

Although, I haven't used any of the IDEs that you have mentioned. But, I think, the popularity of Hibernate has helped it to gain support by most of the major IDEs. And, it may well be incorporated in RAD or RSA.

Also, I understand that it could be quite overwhelming to be introduced to so many new terminologies and technologies after progressing from J2SE. I would suggest you to go through as many examples as possible. Modify them to understand more, and basically just play with it. You will be up to speed in no time.