📄 connectsql.java~104~
字号:
package netbar;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Vector;
import java.sql.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class connectSQL {
Connection con;
Statement s;
// int power=2;
// ResultSet rs;
public connectSQL(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException ce){
ce.printStackTrace();
}
try {
String url = "jdbc:odbc:st0602"; //数据源名st0602
con= DriverManager.getConnection(url);
s=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
// ResultSet rs=s.executeQuery("select * from "+tabname);
}catch(SQLException ce){
ce.printStackTrace();
}
}
public boolean denglu(String name, String psw) {
try {
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rst = st.executeQuery("select * from manager where name='" + name + "' and password='" + psw + "'");
if (rst.next()){
rst.close();
st.close();
return true;
}
rst.close();
st.close();
return false;
} catch (Exception sqle) {
sqle.printStackTrace();
return false;
}
}
public float getMemberbalance(String cardid){
try {
s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rsp = s.executeQuery("select * from member where cardID= '"+cardid+"'");
while(rsp.next()){
return rsp.getFloat(5);
}
rsp.close();
s.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return 0;
}
public float getCommonbalance(String cardid){
try {
s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rsp = s.executeQuery("select * from common where cardID= '"+cardid+"'");
while(rsp.next()){
return rsp.getFloat(5);
}
rsp.close();
s.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return 0;
}
public String getPassword(String name){
try {
s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rsp = s.executeQuery("select * from manager where name= '"+name+"'");
while(rsp.next()){
return rsp.getString(3);
}
rsp.close();
s.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return null;
}
public boolean modifyPassword(String name,String password){
try{
PreparedStatement ps=con.prepareStatement("update manager set password=? where name=?");
ps.setString(1,password);
ps.setString(2,name);
int no=ps.executeUpdate();
if(no>0)
return true;
}catch(SQLException sqle){
sqle.printStackTrace();
}
return false;
}
public int getPower(String name){
try {
s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rsp = s.executeQuery("select * from power where name= '"+name+"'");
while(rsp.next()){
return rsp.getInt(2);
}
rsp.close();
s.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return 100;
}
public Vector getComputer(){
try{
s=con.createStatement();
ResultSet rs=s.executeQuery("select * from computer");
Vector vecAll = new Vector();
while (rs.next()) {
Vector vecTemp = new Vector();
vecTemp.add(rs.getString(1));
vecTemp.add(rs.getString(2));
vecTemp.add(rs.getString(3));
vecTemp.add(rs.getString(4));
vecTemp.add(rs.getDate(5));
vecTemp.add(rs.getDate(6));
vecTemp.add(rs.getString(7));
vecTemp.add(rs.getFloat(8));
vecTemp.add(rs.getFloat(9));
vecTemp.add(rs.getFloat(10));
vecTemp.add(rs.getString(11));
vecTemp.add(rs.getString(12));
vecAll.add(vecTemp);
}
rs.close();
s.close();
return vecAll;
}catch(SQLException sqle){
sqle.printStackTrace();
return null;
}
}
public Vector getMember(){
try{
s=con.createStatement();
ResultSet rs=s.executeQuery("select * from member");
Vector vecAll = new Vector();
while (rs.next()) {
Vector vecTemp = new Vector();
vecTemp.add(rs.getString(1));
vecTemp.add(rs.getString(3));
vecTemp.add(rs.getString(4));
vecTemp.add(rs.getFloat(5));
vecTemp.add(rs.getString(6));
vecTemp.add(rs.getString(7));
vecAll.add(vecTemp);
}
rs.close();
s.close();
return vecAll;
}catch(SQLException sqle){
sqle.printStackTrace();
return null;
}
}
public Vector getCommon(){
try{
s=con.createStatement();
ResultSet rs=s.executeQuery("select * from common");
Vector vecAll = new Vector();
while (rs.next()) {
Vector vecTemp = new Vector();
vecTemp.add(rs.getString(1));
vecTemp.add(rs.getString(3));
vecTemp.add(rs.getString(4));
vecTemp.add(rs.getFloat(5));
vecTemp.add(rs.getString(6));
vecTemp.add(rs.getString(7));
vecAll.add(vecTemp);
}
rs.close();
s.close();
return vecAll;
}catch(SQLException sqle){
sqle.printStackTrace();
return null;
}
}
public boolean addmember(String id,String password,String name,String idcard,String balance,String phone,String info){
try{
PreparedStatement ps=con.prepareStatement("insert into member(cardID,password,name,identitycard,balance,phonenum,info) values(?,?,?,?,?,?,?) ");
ps.setString(1,id);
ps.setString(2,password);
ps.setString(3,name);
ps.setString(4,idcard);
ps.setFloat(5,Float.parseFloat(balance));
ps.setString(6,phone);
ps.setString(7,info);
int no=ps.executeUpdate();
if(no>0)
return true;
}catch(SQLException sqle){
sqle.printStackTrace();
}
return false;
}
public boolean delmember(String id){
try{
PreparedStatement ps=con.prepareStatement("delete from member where cardid=?");
ps.setString(1,id);
int no=ps.executeUpdate();
if(no>0)
return true;
}catch(SQLException sqle){
sqle.printStackTrace();
}
return false;
}
public boolean addcommon(String id,String password){
try{
PreparedStatement ps=con.prepareStatement("insert into common (cardID, password) values(?,?) ");
ps.setString(1,id);
ps.setString(2,password);
int no=ps.executeUpdate();
if(no>0)
return true;
}catch(SQLException sqle){
sqle.printStackTrace();
}
return false;
}
public boolean delcommon(String id){
try{
PreparedStatement ps=con.prepareStatement("delete from common where cardid=?");
ps.setString(1,id);
int no=ps.executeUpdate();
if(no>0)
return true;
}catch(SQLException sqle){
sqle.printStackTrace();
}
return false;
}
public boolean activecommon(String id,String name,String identitycard,String balance,String phonenum,String info){
try{
PreparedStatement ps=con.prepareStatement("update common set name=? ,identitycard=? ,balance=? ,phonenum=? ,info=? where cardID=?");
ps.setString(1,name);
ps.setString(2,identitycard);
ps.setFloat(3,Float.parseFloat(balance));
ps.setString(4,phonenum);
ps.setString(5,info);
ps.setString(6,id);
int no=ps.executeUpdate();
if(no>0)
return true;
}catch(SQLException sqle){
sqle.printStackTrace();
}
return false;
}
public boolean online(String computerid,String cardid,String counttype,String cardtype,String starttime,String yajin,String balance,String state){
try{
System.out.println(computerid);
System.out.println(cardid);
System.out.println(counttype);
System.out.println(cardtype);
System.out.println(starttime);
System.out.println(yajin);
System.out.println(balance);
System.out.println(state);
PreparedStatement ps=con.prepareStatement("update computer set 卡号=?, 计费类型=?, 卡类型=?, 开始时间=?, 押金=?, 余额=?, 使用状态=? where 计算机名=?");
ps.setString(1,cardid);
ps.setString(2,counttype);
ps.setString(3,cardtype);
ps.setString(4,starttime);
ps.setFloat(5,Float.parseFloat(yajin));
ps.setFloat(6,Float.parseFloat(balance));
ps.setString(7,state);
ps.setString(8,computerid);
int no=ps.executeUpdate();
if(no>0)
return true;
}catch(SQLException sqle){
sqle.printStackTrace();
}
return false;
}
public void closeSQL() {
// rs.close();
try{
s.close();
con.close();
}catch(Exception e){
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -