package client;
import java.util.*;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBClient {
DataSource dataSource;
public DBClient(DataSource dataSource) {
this.dataSource = dataSource;
}
public CountInfo checkmoney (String tno) throws Exception{
Connection connect = null;
String strSql;
ResultSet rs;
CountInfo it=new CountInfo();
strSql = "select * from countinfo where tno='"
+ tno+ "'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(strSql);
if ( rs.next()) {
it.setTNO(rs.getString("TNO"));
it.setMONEY(Integer.parseInt(rs.getString("money")));
it.setFREECALL(Integer.parseInt(rs.getString("freecall")));
it.setFREEMES(Integer.parseInt(rs.getString("freemes")));
it.setFREEGPRS(Integer.parseInt(rs.getString("freegprs")));
it.setAVAILABLETIME(rs.getString("availabletime"));
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return it;
}
public Vector Viewcall(String tno) throws Exception{
Connection connect = null;
String strSql;
ResultSet rs;
Vector it=new Vector();
strSql = "select * from cal where tno1='"
+ tno+ "'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(strSql);
while ( rs.next()) {
Call c=new Call();
c.setTno1(rs.getString("tno1"));
c.setTno2(rs.getString("tno2"));
c.setActi(rs.getString("acti"));
c.setRoam(rs.getString("roam"));
c.setCalltime(rs.getTimestamp("calltime"));
c.setTime(rs.getTime("tim"));
it.add(c);
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return it;
}
public Vector Viewmessage(String tno) throws Exception{
Connection connect = null;
String strSql;
ResultSet rs;
Vector it=new Vector();
strSql = "select * from message where tno1='"
+ tno+ "'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(strSql);
while ( rs.next()) {
Message c=new Message();
c.setTno1(rs.getString("tno1"));
c.setTno2(rs.getString("tno2"));
c.setTime(rs.getTimestamp("senttime"));
c.setLength(rs.getInt("messlen"));
it.add(c);
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return it;
}
public Vector Viewgprs(String tno) throws Exception{
Connection connect = null;
String strSql;
ResultSet rs;
Vector it=new Vector();
strSql = "select * from gprs where tno='"
+ tno+ "'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(strSql);
while ( rs.next()) {
Gprs c=new Gprs();
c.setTno(rs.getString("tno"));
c.setTime(rs.getTimestamp("time1"));
c.setBytes(rs.getInt("bytes"));
it.add(c);
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return it;
}
public int ChargeCheck(String chargeno,String password) throws Exception{
Connection connect = null;
String strSql;
ResultSet rs;
int it=0;
strSql = "select * from chargeingcard where cardnum='"
+ chargeno+ "' and cardcode='"+password+"'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(strSql);
if( rs.next()) {
it=rs.getInt("money");
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return it;
}
public void DeleteChargeCard(String chargeno,String password) throws Exception{
Connection connect = null;
String strSql;
strSql = "delete from chargeingcard where cardnum='"
+ chargeno+ "' and cardcode='"+password+"'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
stmt.executeUpdate(strSql);
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return;
}
public void Charge(String tno,int money) throws Exception{
Connection connect = null;
String strSql;
strSql = "update countinfo set money=money+"+money+" where tno='"+tno+"'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
stmt.executeUpdate(strSql);
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return;
}
public int Viewvalue(String tno) throws Exception{
Connection connect = null;
String strSql;
ResultSet rs;
int it=-1;
strSql = "select * from tvalue where tno='"
+ tno+ "'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(strSql);
if( rs.next()) {
it=rs.getInt("value");
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return it;
}
public void Subvalue(String tno,int money) throws Exception{
Connection connect = null;
String strSql;
strSql = "update tvalue set value=value-"+money+" where tno='"+tno+"'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
stmt.executeUpdate(strSql);
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return;
}
public Client Identify(String tno,String code) throws Exception{
Connection connect = null;
String strSql;
ResultSet rs;
Client c=null;
strSql ="select * from clien where tno='"+tno+"' and tcode='"+code+"'";
//update set tno='cec',tname='wx' where tno='cce'
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
rs=stmt.executeQuery(strSql);
if(rs.next()){
c=new Client(rs.getString("tno"));
c.setTname(rs.getString("tname"));
c.setRegtime(rs.getTimestamp("regtime"));
c.setTadd(rs.getString("tadd"));
c.setTcode(rs.getString("tcode"));
c.setTemail(rs.getString("temail"));
c.setTidno(rs.getString("tidno"));
c.setTsex(rs.getString("tsex"));
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return c;
}
public Client GetClient(String tno) throws Exception{
Connection connect = null;
String strSql;
ResultSet rs;
Client c=null;
strSql ="select * from clien where tno='"+tno+"'";
try {
connect = dataSource.getConnection();
Statement stmt = connect.createStatement();
rs=stmt.executeQuery(strSql);
if(rs.next()){
c=new Client(rs.getString("tno"));
c.setTname(rs.getString("tname"));
c.setRegtime(rs.getTimestamp("regtime"));
c.setTadd(rs.getString("tadd"));
c.setTcode(rs.getString("tcode"));
c.setTemail(rs.getString("temail"));
c.setTidno(rs.getString("tidno"));
c.setTsex(rs.getString("tsex"));
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
finally{
if(connect!=null)
connect.close();
}
return c;
}
public void update(Client c,int type) throws Exception{
Connection connect = null;
String strSql;
//strSql ="select * from clien where tn
评论8
最新资源