⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callplsal.java~1~

📁 连接oracle的java库
💻 JAVA~1~
字号:
package com.zp.conn;
//call an anonymous PL/SQL block to show use of a CallableStatement
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.CallableStatement;
import java.sql.Types;
import java.util.Date;
public class CallPlsal
{
    public CallPlsal()
    {
    }
public static void CallAnonymousProc()
{
  Connection connection=null;
  String url="jdbc:oracle:thin:@901-32:xianmap";
  try
  {
    Class.forName("oracle.jdbc:OracleDriver");
    connection=DriverManager.getConnection(url,"system","StudyHard41") ;
  }catch(java.lang.ClassNotFoundException  noclasse)
  {
    System.out.println("get a "+noclasse.getClass() +"\nwith message "+noclasse.getMessage() ) ;
  }catch(java.sql.SQLException  sqle)
  {
    System.out.println("get a "+sqle.getClass() +"\nwith message "+sqle.getMessage() ) ;
  }
  try
  {
    CallableStatement callplsql = connection.prepareCall(
        "{ call begin ?:=SYSDATE+?;end}");
   //register the out parameter
   callplsql.registerOutParameter(1,Types.DATE) ;
   //set the input parameter to 500 days from today
   callplsql.setInt(2,500) ;
   //execute the plsql and return the rsult
   callplsql.execute() ;
   Date result=callplsql.getDate(1) ;
   System.out.println("500 days from today is:"+result) ;
   callplsql.close() ;
  }catch(java.sql.SQLException  sqle)
  {
    System.out.println("get a "+sqle.getClass() +"\nwith message "+sqle.getMessage() ) ;
  }finally
  {
    try
    {
      connection.close();
    }catch(java.sql.SQLException  sqle)
    {
       System.out.println("get a "+sqle.getClass() +"\nwith message "+sqle.getMessage() ) ;
    }
  }
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -