• 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

  • 相关阅读:
    解决EXC_BAD_ACCESS错误的一种方法--NSZombieEnabled
    关于deselectRowAtIndexPath
    CGRectInset、CGRectOffset、等对比整理
    代码设置UITableViewCell 各个组件间距
    UITableViewCell计算行高
    设置UITableView中UIImage的大小
    UILbale自动换行
    根据字体多少使UILabel自动调节尺寸
    ios通过url下载显示图片
    Python【requests】第三方模块
  • 原文地址:https://www.cnblogs.com/kramer/p/3723439.html
Copyright © 2020-2023  润新知