从 eclipse 创建 DatabaseConnection 数据源
我是 Eclipse 新手。 目前正在使用 primefaces 3.1 和 glassfish 3 开发示例 Web 应用程序。
我已经在数据源资源管理器下创建了一个 Oracle 数据库连接。我想知道如何 将其与我的 Web 应用程序集成,以便我可以从我的 Web 应用程序连接到数据库。我知道通过创建 context.xml 并输入以下内容可能足以进行数据库访问,但是是否有办法将数据库连接与我的应用程序集成?这样我就不需要在 context.xml 中硬编码密码。
我过去使用过 Jdeveloper,并通过创建数据库连接来生成 xml 中相应的数据源条目。所以我想知道使用 Eclipse 是否可以实现类似的功能?
非常感谢任何帮助。
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/SampleDB" auth="Container"
type="javax.sql.DataSource"
username="app" password="app"
driverClassName="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:1527/sample"
maxActive="8" />
</Context>
I am new to Eclipse.
Currently developing a sample web application using primefaces 3.1 and glassfish 3.
I have created a oracle database connection under datasource explorer. I would like to know how to
integrate this with my web application, so that I could connect to database from my web application. I know that by creating context.xml and entering the following might be suffice for database access, but are there anyways to integrate database connection with my application? So that I do not need to hard code password in context.xml.
I have used Jdeveloper in the past and by creating a database connection corresponding datasource entries in xml are generated. So I was wondering something similar would be possible using Eclipse?
Any help is highly appreciated.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/SampleDB" auth="Container"
type="javax.sql.DataSource"
username="app" password="app"
driverClassName="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:1527/sample"
maxActive="8" />
</Context>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了为 glassfish 创建数据源的解决方案。
我在 GlassFish 下创建了一个 JDBC 资源,并将连接指向在 Date Source Explorer 下创建的连接。它创建了一个
sun-resources.xml
。我必须手动将其重命名为 glassfish-resource.xml。默认情况下没有密码条目,所以我必须手动添加。当我运行 Web 应用程序时,我收到此错误,因此为了解决此错误,我在 glassfish 管理服务器的 JDBC 连接池中添加了一个属性。现在我可以连接到 Oracle 数据库了。
不知道为什么我必须手动执行两个步骤。此外,默认情况下它还会创建
sun-resources.xml
。也许有人可以指出如何解决这些问题。谢谢
I have found a solution to create datasource for glassfish.
I created a a JDBC Resource under GlassFish and pointed connection to my connection created under Date Source Explorer. It created a
sun-resources.xml
. I had to manually rename this toglassfish-resource.xml
. By default there are no entry for password,so I had to manually add . When I ran my web application I was getting this errorSo to resolve this error I added a property in JDBC Connection Pool in glassfish admin server. Now I could connect to Oracle database.
Not sure why I have to do two steps manually. Besides by default it creates
sun-resources.xml
. Perhaps someone could point out how to workaround these.Thanks