📄 savemoney.java
字号:
package pp;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SaveMoney extends HttpServlet {
/**
* Constructor of the object.
*/
public SaveMoney() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
String accountNo=request.getParameter("AccountID");
double money=Double.parseDouble(request.getParameter("money"));
String type=new String(request.getParameter("select").getBytes("ISO8859_1"));
String fromtime=request.getParameter("savingtime");
dbconn conn=new dbconn();
ResultSet rs=null;
try{
rs=conn.executeQuery("select ACCOUNT_DISCRIM from ACCOUNT where ACCOUNTNUMBER='"+accountNo+"'");
if(rs.next()==true){
if(rs.getString("ACCOUNT_DISCRIM").equals(type)){
if(type.equals("定期帐户")){
String totime=request.getParameter("gettime");
String fd="insert into FDACCOUNT values('"+new Date().getTime()+"','"+accountNo+"',"+money+",'"+0.001*money+"','"+fromtime+"','"+totime+"')";
conn.executeUpdate(fd);
}else{
String rd="insert into RDACCOUNT values('"+new Date().getTime()+"','"+accountNo+"',"+money+",'"+0.0005*money+"','"+fromtime+"')";
conn.executeUpdate(rd);
}
String sq="select BALANCE from SAVINGSACCOUNT where ACCOUNTNUMBER='"+accountNo+"'";
rs=conn.executeQuery(sq);
rs.next();
double sum=money+rs.getDouble("BALANCE");
String sql="update SAVINGSACCOUNT set balance="+sum+" where ACCOUNTNUMBER='"+accountNo+"'";
conn.executeUpdate(sql);
conn.executeUpdate("insert into TRANSACTION (TRANSACTIONID,DATEOFTRANSACTION,AMOUNT,TYPEOFTRANSACTION,OWNEDTRANSACTIONS_ACCOUNTNUM19)values('"+new Date().getTime()+"','"+df.format(new Date())+"',"+money+",'收入','"+accountNo+"')");
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE>");
out.println("</HEAD>");
out.println(" <BODY>");
out.println("操作已成功!<BR>");
out.println(" </BODY>");
out.println("</HTML>");
}else{
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE>");
out.println("</HEAD>");
out.println(" <BODY>");
out.println("帐户类型与帐号不匹配!<BR>");
out.println(" </BODY>");
out.println("</HTML>");
}
}else{
//conn.conn.commit();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE>");
out.println("</HEAD>");
out.println(" <BODY>");
out.println("该帐户不存在!<BR>");
out.println(" </BODY>");
out.println("</HTML>");
}
conn.closeConn();
}catch(Exception e){
e.printStackTrace();
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -