?? personaljob.java
字號:
package qiuzhi;
import java.sql.*;
import java.util.*;
import java.security.*;
public class personaljob
{
private Connection conn = null;
public String error = null; //錯誤信息
private String username = null; //登錄用戶名
private String password = null; //登錄密碼
private String user_id = null;
//初始化,進行數(shù)據(jù)庫驅動的加載和數(shù)據(jù)庫的連接
public boolean init(String OracleDriver,String OracleUrl,String OracleUser,String OraclePsw)
{
try
{
Class.forName(OracleDriver);
this.conn = DriverManager.getConnection(OracleUrl,OracleUser,OraclePsw);
return true;
}
catch(Exception e)
{
this.error = e.toString();
return false;
}
}
//返回中文字符
public String getStr(String str)
{
try
{
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO8859-1");
String temp = new String(temp_t);
return temp;
}
catch(Exception e)
{
return null;
}
}
//HTML特殊字符轉換
public String HtmlSpecialChars(String str)
{
if(str == null||str.equals(""))
{
return str;
}
StringBuffer temp = new StringBuffer();
int i = 0;
while(i < str.length())
{
//將\n轉換成<br>
if(str.charAt(i) == '\n')
{
temp = temp.append("<br>");
}
//將空格轉換成
else if(str.charAt(i) == ' ')
{
temp = temp.append(" ");
}
//將<轉換成<
else if(str.charAt(i) == '<')
{
temp = temp.append("<");
}
//將>轉換成>
else if(str.charAt(i) == '>')
{
temp = temp.append(">");
}
else
{
temp = temp.append(str.substring(i,i+1));
}
i++;
}
String okstring = temp.toString();
return okstring;
}
//設置登錄用戶名
public void setUsername(String user)
{
this.username = user;
}
//設置密碼
public void setPasswrod(String psw)
{
this.password = psw;
}
public String getUserID()
{
return this.user_id;
}
public int logcheck()
{
if(this.username == null || this.password == null)
{
return -1;
}
else
{
int i = 0;
try
{
String query = "select * from USERS where username='"+this.username+"' and password='"+this.password+"'";
PreparedStatement ps = this.conn.prepareStatement(query);
ResultSet res = ps.executeQuery();
if(res.next())
{
this.user_id = String.valueOf(res.getInt("id"));
i = Integer.parseInt(res.getString("role"));
}
else
{
i = -1;
}
res.close();
ps.close();
return i;
}
catch(Exception e)
{
this.error = e.toString();
return -1;
}
}
}
public int getUserID(String username, String password)
{
ResultSet rs = null;
Statement st = null;
try
{
String sql = "select id from USERS where username = '"+username+"' and password='"+password+"'";
st = this.conn.createStatement();
rs = st.executeQuery(sql);
int re = 0;
if(rs.next())
{
re = rs.getInt("id");
}
return re;
}
catch(Exception e)
{
return 0;
}
}
public ResultSet getJobsSimply()
{
String query = "select a.id,cop_id,job_name,job_addr,job_get,job_sta,job_end,job_grad,job_lang,cop_name from JOBS a,COMPANY b where b.id = a.cop_id order by a.id desc";
ResultSet res = null;
try
{
PreparedStatement ps = this.conn.prepareStatement(query);
res = ps.executeQuery();
return res;
}
catch(Exception e)
{
this.error = e.toString();
return null;
}
}
public ResultSet getCopInfo(String id)
{
if(id == null || this.username == null || id == "" || this.username == "")
return null;
String query = "select a.*, b.name from COMPANY a,USERS b where a.id="+id+" and a.user_id = b.id";
ResultSet res = null;
try
{
PreparedStatement ps = this.conn.prepareStatement(query);
res = ps.executeQuery();
return res;
}
catch(Exception e)
{
this.error = e.toString();
return null;
}
}
public ResultSet getJobInfo(String id)
{
if(id == null || this.username == null || id == "" || this.username == "")
return null;
String query = "select * from JOBS where id="+id;
ResultSet res = null;
try
{
PreparedStatement ps = this.conn.prepareStatement(query);
res = ps.executeQuery();
return res;
}
catch(Exception e)
{
this.error = e.toString();
return null;
}
}
public boolean addJob(String cop_id,String job_name,String job_mann,String job_addr,String job_num,String job_get,String job_sta,String job_end,String job_age1,String job_age2,String job_grad,String job_lang,String job_expe,String job_oget,String job_odem)
{
try
{
String sql = new String("select max(id) from JOBS");
PreparedStatement ps = this.conn.prepareStatement(sql);
ResultSet rs1 = ps.executeQuery();
int id = 0;
if(rs1.next())
{
id = rs1.getInt(1);
}
id = id + 1;
ps = null;
sql = null;
sql = new String("INSERT INTO JOBS(id,cop_id,job_name,job_mann,job_addr,job_num,job_get,job_sta,job_end,job_age1,job_age2,job_grad,job_lang,job_expe,job_oget,job_odem");
sql += "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
ps = this.conn.prepareStatement(sql);
ps.setInt(1,id);
ps.setString(2,cop_id);
ps.setString(3,job_name);
ps.setInt(4,Integer.parseInt(job_mann));
ps.setString(5,job_addr);
ps.setInt(6,Integer.parseInt(job_num));
ps.setString(7,job_get);
ps.setInt(8,Integer.parseInt(job_sta));
ps.setInt(9,Integer.parseInt(job_end));
ps.setInt(10,Integer.parseInt(job_grad));
ps.setInt(11,Integer.parseInt(job_age1));
ps.setInt(12,Integer.parseInt(job_age2));
ps.setInt(13,Integer.parseInt(job_lang));
ps.setInt(14,Integer.parseInt(job_expe));
ps.setString(15,job_odem);
ps.setString(16,job_oget);
int ok = ps.executeUpdate();
if(ok==1)
{
ps.close();
this.conn.close();
return true;
}
else
{
ps.close();
this.conn.close();
return false;
}
}
catch(Exception e)
{
this.error = e.toString();
return false;
}
}
public boolean deleteJob(String id)
{
if(id == null || this.username == null || id == "" || this.username == "")
return false;
String query = "delete from JOBS where id="+id;
try
{
PreparedStatement ps = this.conn.prepareStatement(query);
int res = ps.executeUpdate();
ps = null;
query = "delete from resume where job_id = "+id;
ps = this.conn.prepareStatement(query);
ps.executeUpdate();
ps = null;
query = "delete from reply where job_id = "+id;
ps = this.conn.prepareStatement(query);
ps.executeUpdate();
if(res == 1)
{
ps.close();
return true;
}
else
{
ps.close();
return false;
}
}
catch(Exception e)
{
this.error = e.toString();
return false;
}
}
public String[] sendGetInfo(String user_id,String job_id)
{
String query = null;
String[] info = new String[3];
try
{
query = "select * from RESUME where user_id="+user_id+" and job_id="+job_id;
PreparedStatement ps = this.conn.prepareStatement(query);
ResultSet res = ps.executeQuery();
//int i = 0;
if(res.next())
{
info[0] = res.getString("cop_name");
info[1] = res.getString("job_name");
info[2] = res.getString("intro");
//info[3] = res.getInt("id");
ps.close();
return info;
}
else
{
ps = null;
res = null;
query = "select a.cop_name,b.job_name from COMPANY a, JOBS b where b.id ="+job_id+" and a.id = b.cop_id";
ps = this.conn.prepareStatement(query);
res = ps.executeQuery();
if(res.next())
{
info[0] = res.getString(1);
info[1] = res.getString(2);
info[2] = "";
ps.close();
return info;
}
else
{
return null;
}
}
}
catch(Exception e)
{
this.error = e.toString();
return null;
}
}
public boolean sending(String[] info)
{
String id = info[0];
String intro = this.HtmlSpecialChars(info[1]);
if(id == null || id.equals(""))
{
return false;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -