如果你要往类OracleJavaProc中添加一个相关的存储过程方法,是如何对其进行开发呢?以下的文章就是其正确的步骤的介绍,首先是把dropjava, 改程序,再是loadjava。以下就是详细内容的描述。
e.g.修改OracleJavaProc类内容如下:
importjava.sql.*; importoracle.jdbc.*; publicclassOracleJavaProc...{ Addasalgradetothedatabase. publicstaticvoidaddSalGrade(intgrade,intlosal,inthisal)...{ System.out.println("CreatingnewsalgradeforEMPLOYEE..."); try...{ Connectionconn= DriverManager.getConnection("jdbc:default:connection:"); Stringsql= "INSERTINTOsalgrade"+ "(GRADE,LOSAL,HISAL)"+ "VALUES(?,?,?)"; PreparedStatementpstmt=conn.prepareStatement(sql); pstmt.setInt(1,grade); pstmt.setInt(2,losal); pstmt.setInt(3,hisal); pstmt.executeUpdate(); pstmt.close(); } catch(SQLExceptione)...{ System.err.println("ERROR!AddingSalgrade:" +e.getMessage()); } } publicstaticintgetHiSal(intgrade) ...{ try...{ Connectionconn= DriverManager.getConnection("jdbc:default:connection:"); Stringsql="SELECThisalFROMsalgradeWHEREgrade=?"; PreparedStatementpstmt=conn.prepareStatement(sql);pstmt.setInt(1,grade); ResultSetrset=pstmt.executeQuery(); intres=0; if(rset.next()) ...{ res=rset.getInt(1); } rset.close(); returnres; } catch(SQLExceptione) ...{ System.err.println("ERROR!QueryingSalgrade:" +e.getMessage()); return-1; } } }
相关文章
标签:Oracle