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();
        }    }}

更多请见:http://www.mark-to-win.com/tutorial/java_10_oraclehelloworld.html

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值