• 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

  • 相关阅读:
    Linux 常用命令总结(二)
    Linux(CentOS7)使用 RPM 安装 mysql 8.0.11
    Linux(CentOS7) 相关软件安装
    8、js——字符串
    7、js——数组
    6、js——创建对象方式
    5、js——this说明
    4、js——函数
    4、js——对象
    2、js编写位置
  • 原文地址:https://www.cnblogs.com/kramer/p/3723439.html
Copyright © 2020-2023  润新知