DZone Forums
Go Back   DZone Forums > Community > Tools & IDEs > Eclipse
Reload this Page how do you connect a java project to a database
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jun 2009
Default how do you connect a java project to a database - 06-08-2009, 03:05 PM

Hello good people,
Seems like such a simple thing, but I can't find good instructions on it!
New to eclipse, I set up a project on Eclipse 3.4 and Tomcat; I set up the mysql database and see the tables ; but when I browse to the project and try to log in, the log in doesn't work, so I assume I don't know how to point the project to the database.
Thanks!
Reply With Quote
  (#2 (permalink)) Old
Moderator
 
jwenting's Avatar
 
Posts: 99
Thanks: 0
Thanked 8 Times in 8 Posts
Join Date: Feb 2008
Send a message via MSN to jwenting
Default 06-09-2009, 01:14 AM

RTFM. If it's not in the manual and you can't figure it out without for yourself, the tool is the wrong one for you.
Reply With Quote
  (#3 (permalink)) Old
Member
 
Posts: 17
Thanks: 1
Thanked 2 Times in 2 Posts
Join Date: Jan 2009
Angry 06-09-2009, 04:05 AM

That's the reason why I really like forums like this one.

I'm into programming for nearly 30 years, and sometimes I fail to find the solution for a problem which is easier to solve than I expected. When I'm desperate enough, I might ask some forum for help and every so often I find someone who shows me the tree inside the forest. I wonder if there is anybody out there who never asked a question that seemed too easy to answer to some others.

I think rudeness as we found it in jwentings answer is at the very least unpolite and is definetily not the intention of this forum, is it?
Reply With Quote
  (#4 (permalink)) Old
Member
 
Posts: 25
Thanks: 0
Thanked 2 Times in 2 Posts
Join Date: Feb 2008
Default 06-09-2009, 09:40 PM

Your problem description is too vague and does not contain enough information for anyone to see what you are asking.

From what I read, you run the application and try to log in, but the login fails. Maybe the application is taking your userid/password and looking it up in database and not finding match?

Or maybe, application cannot connect to database to verify userid/password?

Is the application connecting to the database at all?

Any error messages?

There is not much information in your original post to even try to respond.
Reply With Quote
  (#5 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jun 2009
Default 06-09-2009, 09:49 PM

I agree. I just joind this forum, and if that is the quality and tone of response I can expect from the MODERATOR I doubt I'll be spending much time here. He might at least have provided a link to the topic in the, er, FM.

elicia (if you're even bothering to follow this thread after being flamed),
You need to create a datasource configuration for Tomcat. The contents vary by database, but at minimum you need to specify the driver name and the URL for the database, just as you would when using driver manager. Define a resource ref for the datasource in your web.xml so you can look it up by its JNDI name from your application code. You'd then call getConnection() on the returned datasource, optionally providing an id and password (the datasource could provide these, too).

You should be able to find many samples on he web if you search "tomcat MySQL datasource".

If you just want to access the database from within eclipse (rather than from a web application) you'll find that more straightforward with WTP (Ganymede) or MyEclipse than vanilla eclipse. To get your feet wet you might play around with an apache derby database first (install the plugins, then right-click on your project and look for the "Apache Derby... Add Apache Derby Nature" selection in the context menu).

Good luck!
Reply With Quote
  (#6 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jun 2009
Default Got it - 06-13-2009, 08:32 PM

Thanks guys! Thanks to you I was able to get it working. There are good people in the world, unlike the childish moderator.
Reply With Quote
  (#7 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jun 2009
Default 06-13-2009, 11:54 PM

Great! Have fun...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create A Java Project in Eclipse by program or via an API dinoo Eclipse 1 11-10-2009 03:18 AM
how to create a java project programmatically during run time ? pratibha Eclipse 2 05-22-2009 05:35 PM
How to connect jdbc with sql server avijit123 Java 1 04-06-2009 08:21 PM
How to connect servlet in Eclipse avijit123 C & C++ 0 04-06-2009 02:24 PM
new bee creating a maven java project miroconnect@yahoo.com Eclipse 0 10-23-2008 12:54 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com