如何在 Eclipse 中设置 JDBC?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10882475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 21:06:15  来源:igfitidea点击:

how to setup JDBC in Eclipse?

eclipsejdbcinstallationdriver

提问by LoveMeow

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.

我有 eclipse 和 j 开发人员,我对 eclipse 更舒服。我想知道如何在 eclipse 中设置 JDBC 驱动程序,我从 oracle.com 下载了一个驱动程序,但是在单击“外部 jars”后浏览时它没有出现在任何地方在“库”选项卡中的“java 构建路径”中。我的数据库是 Oracle 速成版。

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.

java应用程序开发有什么好的pdf或教程吗?我想制作一个前端应用程序,在其中将数据输入到字段中并将其插入到数据库中,并使其在输入例如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

这需要什么材料?我不想学得太深,但我想在这个过程中学习(这不是一个项目,只是我这个月想要实现的)所以我猜我需要 1.一本关于awt,swing classes 2. 我需要设置这个 JDBC 东西我不明白如何在 eclipse 中启动和运行它,我输入代码它给我错误。3.一本关于如何将java连接到oracle express edition DB的书。我有 JDK 1.7.0.0.3

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

提前致谢(我是初学者;))

回答by Android Developer

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.

如果您想将 JAR 文件包含到您的 Eclipse 项目中,您通常会在项目文件夹中创建一个“lib”文件夹,并将该文件放在那里。然后您需要告诉 eclipse 将它包含在您的类路径中,以便您的代码将在 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.

要做到这一点: - 进入项目的属性 - 在左侧栏中选择“Java 构建路径” - 选择窗口中间部分的“库”选项卡 - 单击添加 JAR 按钮 - 这将为您提供您在 eclipse 中的项目列表 - 展开您的项目并进入 lib 文件夹 - 您的 jar 将在那里。- 选择 JAR,单击确定,然后再次退出属性窗口。

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

或者,您只需右键单击该 jar,然后单击 BuildPath->Add to Build Path。

回答by Logan

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.

从 Build path 中选择 Add External Jar 选项,然后浏览到 Jar 下载的位置,选择它并添加它。

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.

如果在浏览构建路径时找不到 Jar,请检查 Windows 资源管理器中的位置并确认它是您要搜索的位置。

回答by april26

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.

您询问了如何“在 eclipse 中设置 jdbc”。这是我对你的问题的看法。如果这不是您问题的答案,也许它会帮助其他人。

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

另外 - 我正在使用开普勒日食。(真正基于开普勒的jboss dev studio版本)

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)

单击添加...并按照提示操作。此时您将能够测试连接。Eclipse 让一切变得一目了然!(点击测试连接按钮)

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.

至于启用 JPA 的应用程序,可能有一种方法可以让 eclipse 设置它(即右键单击您的项目,并且上下文菜单中可能有一些内容)。它会在正确的位置设置一个persistence.xml 文件,也许还有其他的东西。我不知道我的头顶。

Hope this helps.

希望这可以帮助。

回答by Jesus

add a classnotfound exception. like this:

添加一个 classnotfound 异常。像这样:

try {

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

} catch (ClassNotFoundException e) {

    e.printStackTrace();

}