如果你要往類OracleJavaProc中添加一個相關的存儲過程方法,是如何對其進行開發呢?以下的文章就是其正確的步驟的介紹,首先是把dropjava, 改程序,再是loadJava。以下就是詳細內容的描述。
e.g.修改OracleJavaProc類內容如下:
- import Java.sql.*;
- import Oracle.jdbc.*;
- public class OracleJavaProc ...{
- Add a salgrade to the database.
- public static void addSalGrade(int grade, int losal, int hisal) ...{
- System.out.println("Creating new salgrade for EMPLOYEE...");
- try ...{
- Connection conn =
- DriverManager.getConnection("jdbc:default:connection:");
- String sql =
- "INSERT INTO salgrade " +
- "(GRADE,LOSAL,HISAL) " +
- "VALUES(?,?,?)";
- PreparedStatement pstmt = conn.prepareStatement(sql);
- pstmt.setInt(1,grade);
- pstmt.setInt(2,losal);
- pstmt.setInt(3,hisal);
- pstmt.executeUpdate();
- pstmt.close();
- }
- catch(SQLException e) ...{
- System.err.println("ERROR! Adding Salgrade: "
- + e.getMessage());
- }
- }
- public static int getHiSal(int grade)
- ...{
- try ...{
- Connection conn =
- DriverManager.getConnection("jdbc:default:connection:");
- String sql = "SELECT hisal FROM salgrade WHERE grade = ?";
- PreparedStatement pstmt = conn.prepareStatement(sql);pstmt.setInt(1, grade);
- ResultSet rset = pstmt.executeQuery();
- int res = 0;
- if (rset.next())
- ...{
- res = rset.getInt(1);
- }
- rset.close();
- return res;
- }
- catch (SQLException e)
- ...{
- System.err.println("ERROR! Querying Salgrade: "
- + e.getMessage());
- return -1;
- }
- }
- }
上述的相關內容就是對往類OracleJavaProc裡添加一個存儲過程方法的描述,希望會給你帶來一些幫助在此方面。