海鲜超市系统部分代码

/*

* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/package dao;

import java.sql.*;

public class DBTools {

public static Connection getConnection()
{
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ora", "scott", "tiger");
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}

}

public void addMoney(String dept_name, int money) {
try {
DateDAO dao = new DateDAO();
DBTools tools = new DBTools();
Connection conn = tools.getConnection();
String sql = "insert into table_income(income_id,dept_id,daily_income,business_date,lst_mod_timestamp,dept_name ) values("
+ dao.getMax1()
+ ","
+ dao.getMax2()
+ ",?,sysdate,sysdate-30,?)";
System.out.println(sql);
PreparedStatement state = conn.prepareStatement(sql);

state.setInt(1, money);
state.setString(2, dept_name);
state.execute();        
} catch (SQLException e) {

e.printStackTrace();
}
}
package com.yourcompany.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.yourcompany.struts.form.AddmoneyForm;

import dao.AddDAO;

public class AddmoneyAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AddmoneyForm af = (AddmoneyForm) form;
String dept_name = af.getDept_name();
int daily_income = af.getDaily_income();
AddDAO dao = new AddDAO();
dao.addMoney(dept_name, daily_income);
return mapping.findForward("incomeAdd");
}
}
以上为经理手工输入daily_income;

你可能感兴趣的:(DAO,apache,oracle,sql,struts)