资源简介
很好用的哦,这是我自己写的,我大三的软件工程大作业哦
代码片段和文件信息
package edu.ynu.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DB {
public static Connection getConn() {
Connection conn = null;
try {
Class.forName(“com.mysql.jdbc.Driver“);
conn = DriverManager
.getConnection(“jdbc:mysql://localhost/bank?user=root&password=root“);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static Statement createStmt(Connection conn) {
Statement stmt = null;
try {
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
return stmt;
}
public static ResultSet executeQuery(Statement stmt String sql) {
ResultSet rs = null;
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
/*public static ResultSet executeQuery(Connection conn String sql) {
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
// finally {
// close(stmt);
// }
return rs;
}*/
public static
评论
共有 条评论