资源说明:package book.rssreade;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbManager {
protected static Connection conn;
public static final String CLASS_NAME = "com.mysql.jdbc.Driver";
public static final String CONNET_STR = "jdbc:mysql://localhost/rssreader";
public static Connection getConnection()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/rssreader", "root", "root");
return conn;
} catch (Exception e) {
e.printStackTrace();
}return null;
}
public static ResultSet getResultSet(String sql)
{
boolean bSuccess = true;
Statement stmt = null;
ResultSet rs = null;
Connection con = getConnection();
if (con == null)
bSuccess = false;
if (bSuccess) {
try {
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
bSuccess = false;
}
}
if (bSuccess) {
return rs;
}
return null;
}
public static boolean excute(String sql) {
boolean bSuccess = true;
Statement stmt = null;
Connection con = getConnection();
if (con == null)
bSuccess = false;
if (bSuccess) {
try {
stmt = con.createStatement();
bSuccess = stmt.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
bSuccess = false;
}
}
return bSuccess;
}
public static void releaseConnection() {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。