当前位置: 代码迷 >> Oracle开发 >> 这段java代码用存储过程如何写
  详细解决方案

这段java代码用存储过程如何写

热度:74   发布时间:2016-04-24 07:41:30.0
这段java代码用存储过程怎么写
这段java代码用存储过程怎么写:
public String function_A( String table_name , String obid ) {

  Statement stmt = null;
  ResultSet rs = null;

  String sql = "select * from" + table_name+ "where OBID='"+obid+"'" ;
  rs = stmt.executeQuery( sql ) ;
  
  return rs.getString( "STUDENT_NAME" );
}

------解决方案--------------------
代码迷推荐解决方案:oracle存储过程,http://www.daimami.com/search?q=177537
------解决方案--------------------
Java code
一:无返回值的存储过程存储过程为:CREATE OR REPLACE PROCEDURE TESTA(PARA1 IN VARCHAR2,PARA2 IN VARCHAR2)  ASBEGIN   INSERT INTO HYQ.B_ID (I_ID,I_NAME) VALUES (PARA1, PARA2);END TESTA;然后呢,在java里调用时就用下面的代码:package com.hyq.src; import java.sql.*;import java.sql.ResultSet; public class TestProcedureOne {  public TestProcedureOne() {  }  public static void main(String[] args ){    String driver = "oracle.jdbc.driver.OracleDriver";    String strUrl = "jdbc:oracle:thin:@127.0.0.1:1521: hyq ";    Statement stmt = null;    ResultSet rs = null;    Connection conn = null;    CallableStatement cstmt = null;     try {      Class.forName(driver);      conn =  DriverManager.getConnection(strUrl, " hyq ", " hyq ");      CallableStatement proc = null;      proc = conn.prepareCall("{ call HYQ.TESTA(?,?) }");      proc.setString(1, "100");      proc.setString(2, "TestOne");      proc.execute();    }    catch (SQLException ex2) {      ex2.printStackTrace();    }    catch (Exception ex2) {      ex2.printStackTrace();    }    finally{      try {        if(rs != null){          rs.close();          if(stmt!=null){            stmt.close();          }          if(conn!=null){            conn.close();          }        }      }      catch (SQLException ex1) {      }    }  }}
  相关解决方案