📄 db.java~10~
字号:
package myproject;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.Vector;
import java.sql.*;
public class DB {
private Connection con;
private Statement st;
private ResultSet rs;
public DB() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;DatabaseName=mianmu;","sa","");
st=con.createStatement();
} catch (ClassNotFoundException ex) {
} catch (SQLException ex) {
/** @todo Handle this exception */
}
}
public boolean getblcc(String str) { //增 删 改 函数 return bl 通用
int i = 0;
try {
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 ResultSet Select(String str)
{
try {
rs = st.executeQuery(str);
} catch (SQLException ex) {
}
return rs;
}
public int Update(String str)
{
int x=0;
try {
x = st.executeUpdate(str);
} catch (SQLException ex) {
}
return x;
}
public Vector getuserve(String str) { //查询读者资料 并封装成集合 [duze] 表
Vector ve = new Vector();
jbuser j;
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;DatabaseName=mianmu;","sa","");
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 void Close()
{
if(rs!=null)
try {
rs.close();
} catch (SQLException ex) {
}
if(st!=null)
try {
st.close();
} catch (SQLException ex1) {
}
if(con!=null)
try {
con.close();
} catch (SQLException ex2) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -