how to setup JDBC in Eclipse?
Asked Answered
P

4

13

I have eclipse and j developer,I am more comfortable with eclipse.I want to know how to setup the JDBC driver in eclipse,I downloaded a driver from oracle.com but it does not appear anywhere when I browse after clicking 'external jars' in 'java build path' in "libraries" tab. My database is Oracle express edition.

Are there any good pdf's or tutorials for java application development?I want to make a front end application where I enter data into fields and it inserts into DB,and make it such that we can also retrieve information when we enter for example an ID.

What are the materials required for this?I don't want to learn too deep but I want to learn in the process(this is not a project just something I wanna achieve this month) so I am guessing i need 1. a book on awt,swing classes 2. I need to set this JDBC thing I don't understand how to get it up and running in eclipse,i type code it gives me error. 3.a book on how to connect java to oracle express edition DB. I have JDK 1.7.0.0.3

Thanks in advance(i'm a beginner ;))

Pardo answered 4/6, 2012 at 13:50 Comment(2)
Is your problem that you cannot find the driver in your build path, that is import oracle.jdbc.driver.*; is returning a not found? Or do you need help invoking the driver?Monegasque
i right click example.java then i go to properties and libraries tab,then external jars and i cant find the required jar file! anywhere even tough i downloaded it.Pardo
I
20

If you're wanting to include a JAR file to your Eclipse project, you would generally create a 'lib' folder inside the project folder, and put the file in there. You then need to tell eclipse to include it in your class path so your code will compile and run inside eclipse.

To do that: - Go into the properties of your project - Select 'Java Build Path' in the left hand column - Select the 'Libraries' tab in the centre part of the window - Click the Add JARs button - this will give you a list of your projects in eclipse - expand your project and into the lib folder - your jar will be there. - Select the JAR, click OK, and OK again out of the properties window.

Or, you can just right-click the jar and click BuildPath->Add to Build Path.

Isthmus answered 4/6, 2012 at 16:8 Comment(0)
P
4

Select the option of Add External Jar from the Build path and then browse to the location where the Jar is downloaded, select it and add it.

If you are not able to find the Jar while browsing through build path, check the location in windows explorer and confirm that it is where you are searching for it.

Postmortem answered 5/6, 2012 at 5:51 Comment(2)
yes i did what you said,but it still doesnt seem to make my program work(btw this program works in my friends lappy) it gives me seven errors.Pardo
What are the errors that you are getting? Are there errors related to import?Postmortem
V
4

You asked how to "set up jdbc in eclipse". Here is my take on your question. If this isn't the answer to your question maybe it will help someone else.

Also - I'm using kepler eclipse. (really jboss dev studio version based on kepler)

First set up the driver.

Preferences -> Connectivity -> Driver Definitions

Click Add... and follow the prompts. You will be able to test the connection at this point. Eclipse makes it obvious how! (Click the Test connection button)

Close the Preferences window. In the main window

Window -> Show View... -> Data Source Explorer

Right click on Database Connections. Select New... and follow the prompts.

You'll be able to open the connection and browse your database.

As far as JPA-enabling your application, there may be a way to have eclipse set that up (ie right click on your project and maybe there is something in the context menu). It would set up a persistence.xml file in the right place and maybe other things. I don't know off the top of my head.

Hope this helps.

Verdi answered 10/11, 2015 at 11:22 Comment(0)
B
0

add a classnotfound exception. like this:

try {

    Class.forName("com.mysql.jdbc.Driver");//the class driver

} catch (ClassNotFoundException e) {

    e.printStackTrace();

}
Bayou answered 27/11, 2019 at 10:15 Comment(1)
This is no longer the default... It is " com.mysql.cj.jdbc.Driver" as late as 2022-08-27.Bergeron

© 2022 - 2024 — McMap. All rights reserved.