package pay.system;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
public class manager {
private String dbUrl = "jdbc:mysql://localhost:3306/final";//?useUnicode=true&characterEncoding=utf-8";
private String dbUser="root";
private String dbPwd="1234";
boolean login=false;
int nowyear=2013;
public static void main(String[] args)
{
try {
Class.forName("com.mysql.jdbc.Driver"); //加载MYSQL JDBC驱动程序
System.out.println("Success loading Mysql Driver!");
}
catch (Exception e) {
System.out.print("Error loading Mysql Driver!");
e.printStackTrace();
}
}
public Connection getConnection()throws Exception{
return java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);//,);
}
public void closeConnection(Connection con){
try{
if(con!=null) con.close();
}catch(Exception e){
e.printStackTrace();
}
}
public void closePrepStmt(PreparedStatement prepStmt){
try{
if(prepStmt!=null) prepStmt.close();
}catch(Exception e){
e.printStackTrace();
}
}
public void closeResultSet(ResultSet rs){
try{
if(rs!=null) rs.close();
}catch(Exception e){
e.printStackTrace();
}
}
public boolean checkmanager(String user,String pwd) throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
System.out.println(user+pwd);
try {
con=getConnection();
String selectStatement = "select pass" + " from manage "+" where user='"+user+"';";
System.out.println(selectStatement);
prepStmt = con.prepareStatement(selectStatement);
rs = prepStmt.executeQuery();
while (rs.next())
{
//System.out.println("rs "+rs.getString("pass")+pwd);
if (rs.getString("pass").equals(pwd))
{
login=true;
//System.out.println("true "+rs.getString("pass")+pwd);
}
else
login=false;
}
}finally{
closeResultSet(rs);
closePrepStmt(prepStmt);
closeConnection(con);
}
System.out.println("manager checkmanager "+login);
return login;
}
public boolean insert(String hid,String pid,String area,String syear,String image) throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
boolean intry=false;
try {
System.out.println("manager"+pid);
int area2=Integer.parseInt(area);
int syear2=Integer.parseInt(syear);
con=getConnection();
String insertStatement = "insert into house values('"+hid+"', '"+pid+"',"+area2+","+syear2+",'"+image+"');";
System.out.println(insertStatement);
prepStmt = con.prepareStatement(insertStatement);
prepStmt.execute(insertStatement);
while(syear2<=nowyear)
{
insertStatement = "insert into record values('"+hid+"',null,"+syear2+",0);";
System.out.println(insertStatement);
prepStmt = con.prepareStatement(insertStatement);
prepStmt.execute(insertStatement);
syear2++;
}
intry=true;
}
catch (Exception e1) {
System.out.print("get data error!");
intry=false;
e1.printStackTrace();
}
finally{
closeResultSet(rs);
closePrepStmt(prepStmt);
closeConnection(con);
}
return intry;
}
public String sepid(String chhid) throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
String hid=chhid;
String result="";
try {
System.out.println("manager select "+chhid);
System.out.println("manager select "+hid);
con=getConnection();
String selectStatement = "select pid from house where hid='"+hid+"';";
System.out.println(selectStatement);
prepStmt = con.prepareStatement(selectStatement);
rs = prepStmt.executeQuery();
while (rs.next())
{
result=rs.getString("pid");
}
}
catch (Exception e1) {
result="error";
System.out.print("get data error!");
e1.printStackTrace();
}
finally{
closeResultSet(rs);
closePrepStmt(prepStmt);
closeConnection(con);
}
return result;
}
public String searea(String chhid) throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
String hid=chhid;
String result="";
try {
System.out.println("manager select "+chhid);
System.out.println("manager select "+hid);
con=getConnection();
String selectStatement = "select area from house where hid='"+hid+"';";
System.out.println(selectStatement);
prepStmt = con.prepareStatement(selectStatement);
rs = prepStmt.executeQuery();
while (rs.next())
{
result=rs.getString("area");
}
}
catch (Exception e1) {
result="error";
System.out.print("get data error!");
e1.printStackTrace();
}
finally{
closeResultSet(rs);
closePrepStmt(prepStmt);
closeConnection(con);
}
return result;
}
public String sesyear(String chhid) throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
String hid=chhid;
String result="";
try {
System.out.println("manager select "+chhid);
System.out.println("manager select "+hid);
con=getConnection();
String selectStatement = "select syear from house where hid='"+hid+"';";
System.out.println(selectStatement);
prepStmt = con.prepareStatement(selectStatement);
rs = prepStmt.executeQuery();
while (rs.next())
{
result=rs.getString("syear");
}
}
catch (Exception e1) {
result="error";
System.out.print("get data error!");
e1.printStackTrace();
}
finally{
closeResultSet(rs);
closePrepStmt(prepStmt);
closeConnection(con);
}
return result;
}
public String seimage(String chhid) throws Exception{
Connection con=null;
PreparedStatement prepStmt=null;
ResultSet rs=null;
String hid=chhid;
String result="";
try {
System.out.println("manager select "+chhid);
System.out.println("manager select "+hid);
con=getConnection();
String selectStatement = "select image from house where hid='"+hid+"';";
System.out.println(selectStatement);
prepStmt = con.prepareStatement(selectStatement);
rs = prepStmt.executeQuery();
while (rs.next())
{
result=rs.getString("image");
System.out.print(result);
}
}
catch (Exception e1) {
result="error";
System.out.print("get data error!");
e1.printStackTrace();
}
finally{
closeResultSet(rs);
closePrepStmt(prepStmt);
closeConnection(con);
}
return result;
}
public boolean update(String hid,String pid,S