java当中请给出一个oracle的helloworld例子
2019-10-12 08:29:42来源:博客园 阅读 ()
java当中请给出一个oracle的helloworld例子
[学习笔记]
2.oracle的helloworld例子:
import java.sql.*;
public class OracleHello{
public static void main(String args[]) {
Connection con;
String createString;
createString = "select EMPNO from EMP";
Statement stmt;
try {
/*see above, import sun.jdbc.odbc.JdbcOdbcDriver;*/
/*see above, import sun.jdbc.odbc.JdbcOdbcDriver;for kkk this kind of url connection string, you must
use sun.jdbc.odbc.JdbcOdbcDriver. if you wan to use oracle.jdbc.driver.OracleDriver, you must use
jdbc:oracle:thin:@localhost:1521:qixy */
/*a sound blaster hardware need a driver to function, software draw awave, then when play,
through the driver, hardware can change it to sound you can hear. here your statement can
be sent to the database.
public static Class forName(String className)
throws ClassNotFoundExceptionReturns the Class object associated with the class or interface with the given string name. Invoking this method is equivalent to:
Class.forName(className, true, currentLoader)
where currentLoader denotes the defining class loader of the current class.
For example, the following code fragment returns the runtime Class descriptor for the class named java.lang.Thread:
Class t = Class.forName("java.lang.Thread")
A call to forName("X") causes the class named X to be initialized.
*/
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:qixy", "scott", "tiger");
System.out.println("Connection is ok");
stmt = con.createStatement();
// stmt.execute(createString);
ResultSet rs=stmt.executeQuery(createString);
while(rs.next())
{ String no=rs.getString("EMPNO");
System.out.println(no);
}
stmt.close();
con.close(); }
catch (Exception ex) {
ex.printStackTrace();
} }}
文章转载自原文:https://blog.csdn.net/qq_44594249/article/details/100669095
原文链接:https://www.cnblogs.com/haima1949/p/11652144.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 国外程序员整理的Java资源大全(全部是干货) 2020-06-12
- 2020年深圳中国平安各部门Java中级面试真题合集(附答案) 2020-06-11
- 2020年java就业前景 2020-06-11
- 04.Java基础语法 2020-06-11
- Java--反射(框架设计的灵魂)案例 2020-06-11
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash