数据库常见操作代码(可直接复制粘贴修改提示内容)
2024-12-29 20:44 浏览:53
连接数据库的代码
public class DatabaseConnect {
private Connection conn;
public DatabaseConnect() throws ClassNotFoundException, SQLException{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("load ok");
String url = "jdbc:mysql://localhost:3306/MySQL?user=root&password;=";
conn = DriverManager.getConnection(url);
System.out.println("connect ok");
}
public static void main(String[] args) {
try {
new DatabaseConnect();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet runQuery(String sql) throws SQLException {
Statement statement = conn.createStatement();
ResultSet records = statement.executeQuery(sql);
return records;
}
public void excuteQuery(String sql) throws SQLException {
Statement statement = conn.createStatement();
statement.execute(sql);
}
public void close() throws SQLException{
conn.close();
} 以上就是本篇文章【数据库常见操作代码(可直接复制粘贴修改提示内容)】的全部内容了,欢迎阅览 ! 文章地址:http://w.yusign.com/quote/8114.html
行业
资讯
企业新闻
行情
企业黄页
同类资讯
网站地图
返回首页 述古往 http://w.yusign.com/mobile/ , 查看更多