zoukankan      html  css  js  c++  java
  • A java code

    With the help of LiJun I got a piece of JAVA code. With this code, I can do below things like connect to oracle database with jdbc driver and run sql.

    Below are the Java code. 

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    /**
    *
    * @author xx
    */
    
    public class TestJDBC {
      static Connection conn= null;
      static String url="jdbc:oracle:thin:@pnd:1521:pnd";
      static String username="pnadm";
      static String password="password";
    
      public TestJDBC()
    {
      try{
      String driverclass="oracle.jdbc.driver.OracleDriver";
      Class.forName(driverclass).newInstance();
      conn=DriverManager.getConnection(url,username,password);
       }catch(Exception e){
                            e.printStackTrace();
                            }
      }
      public static void getDate(){
      String sql="select object_name from all_objects where rownum<2";
      try{
            Statement stmt=conn.createStatement();
            ResultSet rs1=stmt.executeQuery(sql);
    
            while(rs1.next()){
                            System.out.print(rs1.getString("object_name")+" ");
                            }
                    }catch(Exception e){
                            e.printStackTrace();
                            }
    
    }
    
    public static void main(String[] args) {
       TestJDBC t = new TestJDBC();
        for (int i=0;i <30 ; i++)
                    t.getDate();
    
         try {
                Thread.sleep(30000);
            } catch (InterruptedException e) {
            }
    
        for (int i=0;i <280 ; i++)
                    t.getDate();
    
         try {
                Thread.sleep(300000);
            } catch (InterruptedException e) {
            }
    
    
     }
    }

    There is something important I need to record down.

    1. You need to specify classpath environment variable for example

    export CLASS_PATH=/opt/oracle/product/10.2/jdbc/lib/ojdbc14.jar

    2. You can get the jdbc driver from oracle directory

  • 相关阅读:
    table首行固定
    JavaScript获取当前日期,昨天,今天日期以及任意天数间隔日期
    Struts2二级菜单联动
    Servlet和Struts2同时使用
    最近的感想
    java.lang.NoClassDefFoundError: javax/el/ELResolver 问题解决
    Event Loop、函数式编程、IO多路复用、事件驱动、响应式、
    Git 的使用(一)
    Linux 硬链接与软链接 目录结构
    并发、并行、同步、异步相关感念
  • 原文地址:https://www.cnblogs.com/kramer/p/3723439.html
Copyright © 2011-2022 走看看