展开全部
public class DbManager {
private Connection con;
private Statement stm;
public DbManager() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bbs",
"sa", "");
} catch (SQLException ex) {
System.out.println(ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
}
}
public int exeSql(String sql) {
try {
stm = con.createStatement();
return stm.executeUpdate(sql);
} catch (SQLException ex) {
return 0;
}
}
public ResultSet query(String sql) {
try {
stm = con.createStatement();
return stm.executeQuery(sql);
} catch (SQLException ex) {
System.out.println(ex.getMessage());
return null;
}
}
public static void main(String[] args) {
DbManager db = new DbManager();
}
}
这个是SQL数据库操作类,在系统窗体里面插入这个可以时间对数据库的增删改查功能!
private Connection con;
private Statement stm;
public DbManager() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bbs",
"sa", "");
} catch (SQLException ex) {
System.out.println(ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
}
}
public int exeSql(String sql) {
try {
stm = con.createStatement();
return stm.executeUpdate(sql);
} catch (SQLException ex) {
return 0;
}
}
public ResultSet query(String sql) {
try {
stm = con.createStatement();
return stm.executeQuery(sql);
} catch (SQLException ex) {
System.out.println(ex.getMessage());
return null;
}
}
public static void main(String[] args) {
DbManager db = new DbManager();
}
}
这个是SQL数据库操作类,在系统窗体里面插入这个可以时间对数据库的增删改查功能!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询