简体   繁体   English

如何通过创建数据源设置我的Java程序(使用jdk no netbeans独立使用)与oracle 10g数据库的连接?

[英]How to set connection for my java program(standalone using jdk no netbeans) with oracle 10g database by creating datasource?

I have downloaded and installed oracle 10g express from internet and it shows as XE. 我已经从Internet下载并安装了oracle 10g express,它显示为XE。 Don't know what it actually means. 不知道它的实际含义。 Now, I have to connect my java program with the database and try creating table and execute queries as I did during my course with SQL server. 现在,我必须将Java程序与数据库连接,并尝试创建表并执行查询,就像在使用SQL Server的过程中一样。 Please guide me how to create the dsn, connect with database and do all my jdbc related programs now with this oracle 10g. 请指导我如何使用此oracle 10g创建dsn,连接数据库并执行所有与jdbc相关的程序。 Please let me know the step by step procedure starting from datasource creation till doing coding for jdbc in java... Thank you!! 请让我知道从数据源创建到在Java中为jdbc进行编码的分步过程。谢谢!!

You can create oracle datasource like this; 您可以像这样创建oracle数据源;

    OracleDataSource ds = new OracleDataSource();
    ds.setDriverType("thin");
    ds.setServerName("yourServerName");
    ds.setPortNumber(1521);
    ds.setDatabaseName("yourDatabaseName");
    ds.setUser("yourUserName");
    ds.setPassword("YourPassword");

And you can get connection like this; 这样您就可以获得连接;

    Connection conn = ds.getConnection();

First of all you have to make the JDBC Connector available to your application. 首先,您必须使JDBC连接器可用于您的应用程序。 To do that download the JDBC connector from oracle ( http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html ) and place it somewhere accesible by your application. 为此,请从oracle( http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html )下载JDBC连接器,并将其放置在应用程序可以访问的位置。

Secondly you have to use this JDBC to create a connection to the database. 其次,您必须使用此JDBC创建与数据库的连接。 There are plenty of examples on SO on how to java code to query the database. 关于SO如何使用Java代码查询数据库有很多示例。

Here is also a nice complete example of what you are looking for : http://www.javaworkspace.com/connectdatabase/connectOracle.do 这也是您正在寻找的一个很好的完整示例: http : //www.javaworkspace.com/connectdatabase/connectOracle.do

UPDATE 更新

This is also a nice file to take a look at that shows you exactly what to do step by step http://pdf.coreservlets.com/first-edition/CSAJSP-Chapter18.pdf 这也是一个不错的文件,可以准确地一步一步地告诉您http://pdf.coreservlets.com/first-edition/CSAJSP-Chapter18.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM