📄 cons.java~23~
字号:
package jxm;
import java.sql.*;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class cons {
public cons() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Connection getcon() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=bookk",
"sa", "ok");
return con;
} catch (Exception ex) {
}
return null;
}
public boolean getbl(String str) { //查询数据库中是否有数据 return boolean
Connection con = null; // 此函数通用
Statement st = null;
ResultSet rs = null;
try {
con = cons.getcon();
st = con.createStatement();
rs = st.executeQuery(str);
if (rs.next()) {
return true;
}
} catch (Exception ex) {
System.out.println(ex);
}
finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (Exception ex) {
System.out.println(ex);
}
}
return false;
}
public ResultSet getrs(String str) { //查询数据库中数据 此函数通用 return resultset
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
con = cons.getcon();
st = con.createStatement();
rs = st.executeQuery(str);
return rs;
} catch (Exception ex) {
System.out.println(ex);
}
return null;
}
public boolean getblcc(String str) { //增 删 改 函数 return bl 通用
Connection con = null;
Statement st = null;
int i = 0;
try {
con = cons.getcon();
st = con.createStatement();
i = st.executeUpdate(str);
// System.out.println(i);
if (i > 0) {
return true;
}
} catch (Exception ex) {
System.out.println(ex);
} finally {
try {
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (Exception ex) {
System.out.println(ex);
}
}
return false;
}
public Vector getbookve(String str) { // 查询图书资料 把图书资料表封装成集合[books]表
Vector ve = new Vector(); /////////////////////
jbbooks j;
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
con = cons.getcon();
st = con.createStatement();
rs = st.executeQuery(str);
while (rs.next()) {
j = new jbbooks();
j.setBnum(rs.getString(1));
j.setBname(rs.getString(2));
j.setBze(rs.getString(3));
j.setBcbs(rs.getString(4));
j.setBtype(rs.getString(5));
j.setBprice(rs.getString(6));
j.setBpage(rs.getString(7));
j.setBaddress(rs.getString(8));
j.setBzt(rs.getString(9));
ve.add(j);
}
return ve;
} catch (Exception ex) {
System.out.println(ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (Exception ex) {
System.out.println(ex);
}
}
return null;
}
public Vector getuserve(String str) { //查询读者资料 并封装成集合 [duze] 表
Vector ve = new Vector();
jbuser j;
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
con = cons.getcon();
st = con.createStatement();
rs = st.executeQuery(str);
while (rs.next()) {
j = new jbuser();
j.setDnum(rs.getString(1));
j.setDname(rs.getString(2));
j.setDsex(rs.getString(3));
j.setDdh(rs.getString(4));
j.setDaddress(rs.getString(5));
ve.add(j);
}
return ve;
} catch (Exception ex) {
System.out.println(ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (Exception ex) {
System.out.println(ex);
}
}
return null;
} //end getserve
public Vector getjbkve(String str) { //查询借出借入资料 并封装成集合 [jhbook] 表
Vector ve = new Vector();
jbjhbook j;
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
con = cons.getcon();
st = con.createStatement();
rs = st.executeQuery(str);
while (rs.next()) {
j = new jbjhbook();
j.setBookid(rs.getString(1));
j.setUserid(rs.getString(2));
j.setStarttime(rs.getDate(3)); //Date
j.setEndtime(rs.getDate(4)); //Date
j.setBorrowtime(rs.getString(5));
j.setYamoney(rs.getString(6));
j.setZumoney(rs.getString(7));
ve.add(j);
}
return ve;
} catch (Exception ex) {
System.out.println(ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (Exception ex) {
System.out.println(ex);
}
}
return null;
} //end getserve
public Vector getbookzt(String str){
Vector ve = new Vector();
jbbookzt j;
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
con = cons.getcon();
st = con.createStatement();
rs = st.executeQuery(str);
while (rs.next()) {
j = new jbbookzt();
j.setBname(rs.getString(1));
j.setYmount(rs.getString(2));
j.setNmount(rs.getString(3));
j.setZmount(rs.getString(4));
ve.add(j);
}
return ve;
} catch (Exception ex) {
System.out.println(ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (Exception ex) {
System.out.println(ex);
}
}
return null;
}
private void jbInit() throws Exception {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -