📄 test1.jsp
字号:
<%@page import="java.sql.*" contentType="text/html;charset=GB2312"%>
<html>
<head></head>
<body>
<%
Connection conn=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:saloryDSN";
String user = "admin";
String password = "";
conn = DriverManager.getConnection(url, user, password);
conn.setAutoCommit(false);//关闭自动提交模式
String sql = "insert into employee values(?,?,?,?,?)";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setInt(1,20);
ps.setString(2,"段金锁");
ps.setString(3,"经理助理");
ps.setString(4,"研发部");
ps.setFloat(5,2000f);
ps.executeUpdate();
Statement sm=conn.createStatement();
sm.executeUpdate("update employee set salory=3800 where 员工姓名='冯雪正'");
conn.commit();//正常情况下提交本次事务
ResultSet rs =sm.executeQuery("select employee.* from employee");
%>
<table border="6" align="center">
<tr bgcolor="d1d1ff">
<th>员工编号</th>
<th>员工姓名</th>
<th>员工职务</th>
<th>所属部门</th>
<th>基本工资</th>
</tr>
<%while(rs.next()){%>
<tr bgcolor="lightblue">
<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>
<%}
rs.close();
// ps.close();
sm.close();
%>
</TABLE>
<%
}//end of try
catch(Exception ex){
out.print(ex.getMessage());
try{
conn.rollback();
}
catch(SQLException e){
out.print(e.getMessage());
}
}
finally{
conn.setAutoCommit(true);
conn.close();
}
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -