这次我没有使用到jsp的标签。
目的是用bean来实现之前用eclipse编辑jsp来调用oracle过程 里面的调用方法。
javabean DataInst :
/*
* Created on 2004-11-4
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author Shaird
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
/**
* @author Shaird
*
* TODO 利用过程插入数据
*/
public class DataInset {
private int EmpId;
private String EmpName;
private String EmpDept;
private int EmpAge;
private boolean EmpIdOk;
private boolean EmpNameOk;
private boolean EmpDeptOk;
private boolean EmpAgeOk;
/**
* 设置雇员id。
* @param emp_id
*/
public void setEmpId(int emp_id){
this.EmpId=emp_id;
EmpIdOk=true;
}
/**
* 获取雇员id。
* @return
*/
private int getEmpId(){
return this.EmpId;
}
/**
* 设置雇员名。
* @param emp_name
*/
public void setEmpName(String emp_name){
this.EmpName=emp_name;
EmpNameOk=true;
}
/**
* 获取雇员名。
* @return
*/
public String getEmpName(){
return this.EmpName;
}
/**
* 设置雇员所在部门。
* @param emp_dept
*/
public void setEmpDept(String emp_dept){
this.EmpDept=emp_dept;
EmpDeptOk=true;
}
/**
* 获取雇员所在部门信息。
* @return
*/
public String getEmpDept(){
return this.EmpDept;
}
/**
* 设置雇员年龄。
* @param emp_age
*/
public void setEmpAge(int emp_age){
this.EmpAge=emp_age;
EmpAgeOk=true;
}
/**
* 获取雇员年龄。
* @return
*/
public int getEmpAge(){
return this.EmpAge;
}
/**
* 检验是否信息齐全。
* @return
*/
public boolean isOk(){
if(EmpIdOk && EmpNameOk && EmpDeptOk && EmpAgeOk){
return true;
}
else
return false;
}
/**
* 发送雇员信息给过程。
* @throws java.io.IOException
*/
public void SendInfo()throws java.io.IOException{
DataSource ds = null;
try{
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/oracle");
Connection conn = ds.getConnection();
CallableStatement empstmt = conn.prepareCall("{call emp_test(?,?,?,?)}");
empstmt.setInt(1,101);
empstmt.setString(2,"张三");
empstmt.setString(3,"人事部");
empstmt.setInt(4,36);
empstmt.executeUpdate();
ctx.close();
conn.close();
} catch(Throwable tt){
}
}
}
调用这个bean的 jsp:
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>用bean调用过程</title>
</head>
<body>
<table>
<tr><td>雇员id</td><td>雇员名</td><td>所在部门</td><td>雇员年龄</td><td>注册时间</td></tr>
<%
DataInset need=new DataInset();
need.setEmpid(101);
need.setEmpName("张三");
need.setEmpDept("人事部");
need.setEmpAge(36);
need.SendInfo();
DataSource ds = null;
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/oracle");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp_info_test");
while(rs.next())
{
out.println("<tr><td>" + rs.getString(1) + "</td><td>" + rs.getString(2) + "</td><td>" + rs.getString(3) + "</td><td>" + rs.getString(4) + "</td><td>" + rs.getString(5) + "</td></tr>");
}
ctx.close();
rs.close();
stmt.close();
conn.close();
%>
</table>
<%=need.isOk()%>
<p>
</body>
</html>
Ok以后要插入这个数据的时候只要简单的调用这个bean就可以了。