5.15

package com.example.yibaifen.Bean;



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 Mysql {
public static Connection conn = null;//链接
public static Statement stmt = null;
public static ResultSet rs = null;
public static PreparedStatement pre = null;
static String url = "jdbc:mysql://211.149.141.23:22012/yibaifen";
static String username = "local2";
static String password = "123456";
public static void getconn(){
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("数据库运行");
conn = DriverManager.getConnection(url,username,password);
stmt = conn.createStatement();

} catch(SQLException se){
// 处理 JDBC 错误
se.printStackTrace();
}catch(Exception e){
// 处理 Class.forName 错误
e.printStackTrace();
}
}
public static void close(){
try {
if (rs!=null){
rs.close();
}
if (stmt!=null){
stmt.close();
}
if (pre!=null){
pre.close();
}
if (conn!=null){
conn.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
posted @ 2024-05-15 22:57  混沌武士丞  阅读(2)  评论(0编辑  收藏  举报