数据库连接与断开:Connection conn=Jdbcutil.open(); &n
数据库连接与断开:Connection conn=Jdbcutil.open();
Jdbcutil.close(conn);
package 数据库.连接;
import java.sql.*;
public class Jdbcutil {
private static String driver;
private static String url;
private static String userName;
private static String passWord;
static{
driver="com.Mysql.jdbc.Driver";
url="jdbc:mysql://localhost:3306/网页数据";
userName="root";
passWord="123";
}
public static Connection open(){
try {
Class.forName(driver);
return DriverManager.getConnection(url,userName,passWord);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return null;
}
public static void close(Connection conn){
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
}
--结束END--
本文标题: 数据库连接
本文链接: https://www.lsjlt.com/news/41226.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0