如果你要往类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里添加一个存储过程方法的描述,希望会给你带来一些帮助在此方面。
【编辑推荐】