📄 facilitymanage.java
字号:
/*
* Created on 2008-12-29
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package JavaBean;
/**
* @author zhou
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @version 1.0
* @author
*/
public class FacilityManage
{
public Connection getConnection()
{
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/caims";
String user = "root";
String password = "111111";
conn = DriverManager.getConnection(url,user,password);
return conn;
}catch(Throwable e)
{
System.out.println(e);
}
return null;
}
public ArrayList select(String sql)
{
ArrayList result = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
Facility job = new Facility();
job.setFacilityID(rs.getString("FacilityID"));
job.setKind(rs.getString("Kind"));
job.setExpense(rs.getString("Expense"));
job.setFacilityState(rs.getString("FacilityState"));
job.setRecordID(rs.getString("RecordID"));
job.setUserName(rs.getString("UserName"));
job.setDate(rs.getString("Date"));
job.setStartTime(rs.getString("StartTime"));
job.setEndTime(rs.getString("EndTime"));
job.setOrderState(rs.getString("OrderState"));
result.add(job);
}
}
catch(Throwable e)
{
System.out.println(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(stmt != null)
{
stmt.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(conn != null)
{
conn.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
}
return result;
}
public ArrayList query(String sql)
{
ArrayList result = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
Facility job = new Facility();
job.setFacilityID(rs.getString("FacilityID"));
job.setKind(rs.getString("Kind"));
job.setExpense(rs.getString("Expense"));
job.setFacilityState(rs.getString("FacilityState"));
job.setDate(rs.getString("Date"));
job.setStartTime(rs.getString("StartTime"));
job.setEndTime(rs.getString("EndTime"));
result.add(job);
}
}
catch(Throwable e)
{
System.out.println(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(stmt != null)
{
stmt.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(conn != null)
{
conn.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
}
return result;
}
public ArrayList orderquery(String sql)
{
ArrayList result = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
Facility job = new Facility();
job.setFacilityID(rs.getString("FacilityID"));
job.setDate(rs.getString("Date"));
job.setStartTime(rs.getString("StartTime"));
job.setEndTime(rs.getString("EndTime"));
result.add(job);
}
}
catch(Throwable e)
{
System.out.println(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(stmt != null)
{
stmt.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(conn != null)
{
conn.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
}
return result;
}
public ArrayList datequery(String sql)
{
ArrayList result = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
Facility job = new Facility();
job.setFacilityID(rs.getString("FacilityID"));
job.setKind(rs.getString("Kind"));
job.setExpense(rs.getString("Expense"));
job.setFacilityState(rs.getString("FacilityState"));
job.setDate(rs.getString("Date"));
result.add(job);
}
}
catch(Throwable e)
{
System.out.println(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(stmt != null)
{
stmt.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(conn != null)
{
conn.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
}
return result;
}
public void insert(String sql)
{
Connection conn = null;
PreparedStatement ps = null;
try
{
conn = getConnection();
ps = conn.prepareStatement(sql);
ps.executeUpdate();
}
catch(Throwable e)
{
System.out.println(e);
}
finally
{
try
{
if(ps != null)
{
ps.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(conn != null)
{
conn.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
}
}
public void update(String sql)
{
Connection conn = null;
PreparedStatement ps = null;
try
{
conn = getConnection();
ps = conn.prepareStatement(sql);
ps.executeUpdate();
}
catch(Throwable e)
{
System.out.println(e);
}
finally
{
try
{
if(ps != null)
{
ps.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(conn != null)
{
conn.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
}
}
public void delete(String sql)
{
Connection conn = null;
PreparedStatement ps = null;
try
{
conn = getConnection();
ps = conn.prepareStatement(sql);
ps.executeUpdate();
}
catch(Throwable e)
{
System.out.println(e);
}
finally
{
try
{
if(ps != null)
{
ps.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
try
{
if(conn != null)
{
conn.close();
}
}
catch(Throwable e)
{
System.out.println(e);
}
}
}
public ResultSet checkFacility(String sql)
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch(Throwable e)
{
System.out.println(e);
}
return rs;
}
public ArrayList checkTime(HttpServletRequest request)
{
ArrayList al = new ArrayList();
try{
int i = 0;
int j = 0;
FacilityManage db = new FacilityManage();
HttpSession session = request.getSession();
String Kind = request.getParameter("Kind");
String StartTime = request.getParameter("StartTime");
String EndTime = request.getParameter("EndTime");
String sql3="select * from facilityinformation";
ResultSet rs3 = db.checkFacility(sql3);
int a = Integer.parseInt(StartTime);
int b = Integer.parseInt(EndTime);
if(null != session.getAttribute("Query") && (a<b))
{
while(rs3.next())
{
i = 0;
j = 0;
String sql="select * from memberfacility,facilityinformation where memberfacility.FacilityID=facilityinformation.FacilityID and memberfacility.FacilityID='"+rs3.getString("FacilityID")+"' and Kind ='"+Kind+"' and Date = '"+session.getAttribute("Query")+"' and FacilityState = '0'";
String sql2="select * from memberfacility,facilityinformation where memberfacility.FacilityID=facilityinformation.FacilityID and memberfacility.FacilityID='"+rs3.getString("FacilityID")+"' and Kind ='"+Kind+"' and Date = '"+session.getAttribute("Query")+"' and FacilityState = '0' and (StartTime >= '"+EndTime+"' or '"+StartTime+"' >= EndTime)";
ResultSet rs = db.checkFacility(sql);
ResultSet rs2 = db.checkFacility(sql2);
while(rs.next())
{
i++;
}
while(rs2.next())
{
j++;
}
if((i == j)&&(rs3.getString("Kind").equals(Kind))&&(rs3.getString("FacilityState").equals("0")))
{
Facility f = new Facility();
f.setFacilityID(rs3.getString("FacilityID"));
f.setKind(rs3.getString("Kind"));
f.setExpense(rs3.getString("Expense"));
f.setFacilityState(rs3.getString("FacilityState"));
f.setDate((String)session.getAttribute("Query"));
al.add(f);
}
}
}
}catch(Throwable e)
{
System.out.println(e);
}
return al;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -