zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    “花田喜事” 婚庆网站策划
    discuz 模块模板标签说明 DIY模块模板语法详解
    discuz x2.5 广告位开发学习(第二步:制作)
    DiscuzX2.5完整目录结构【模板目录template】
    Webservice 安全性访问
    X2.5 怎么关闭个人空间
    心中有佛,看人即佛;心中有屎,看人即屎
    discuz x2.5 广告位开发学习(第一步:摸索)
    UVA 128 Software CRC
    UVA 10791 Minimum Sum LCM
  • 原文地址:https://www.cnblogs.com/haima1949/p/11652144.html
Copyright © 2011-2022 走看看