简体   繁体   English

适用于Java 1.7版本的oracle 11g数据库连接

[英]oracle 11g database connection for java 1.7 version

can we connect to oracle 11g from java 1.7 version. 我们可以从Java 1.7版本连接到oracle 11g吗? if yes, how? 如果是,如何? and what classpath do we need to set to avoid class not found error for the class OracleDriver? 以及我们需要设置什么类路径以避免类OracleDriver的类未找到错误?

AFAIK there's no difference from previous versions. AFAIK与以前的版本没有任何区别。 This is Oracle's documentation: 这是Oracle的文档:

http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html

What you need is the driver (a jar file downloadable from Oracle) to be in your classpath and loading it using reflection before you use it (there's an example in the link). 您需要的是驱动程序(可从Oracle下载的jar文件)进入您的类路径,并在使用前使用反射将其加载(链接中有一个示例)。

您可以从oracle 11g驱动程序下载驱动程序并将其添加到classpath。

For any java program, any of your library files should be included in the path of CLASSPATH. 对于任何Java程序,任何库文件都应包含在CLASSPATH的路径中。 For example, you have saved your library MyLibrary.jar in /home/program/lib , then you should execute export CLASSPATH=$CLASSPATH:/home/program/lib 例如,您已将库MyLibrary.jar保存在/ home / program / lib中,则应执行export CLASSPATH = $ CLASSPATH:/ home / program / lib

For JDBC, you can download JDBC library from Oracle website. 对于JDBC,您可以从Oracle网站下载JDBC库。 You put the JAR file into the CLASSPATH path you are using, then you can call it. 将JAR文件放入正在使用的CLASSPATH路径中,然后可以调用它。

For flexible design, you should not hardcode the classname of JDBC driver. 为了进行灵活的设计,您不应硬编码JDBC驱动程序的类名。 Instead, you can define it in an external text file so that you can change the value of JDBC driver classname without changing codes. 相反,您可以在外部文本文件中定义它,以便可以更改JDBC驱动程序类名的值而无需更改代码。

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

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