📄 db.java
字号:
import java.sql.*;
public class DB {
public static Connection getConn()
{
Connection conn=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/bbs?user=root&password=root");
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
return conn;
}
public static Statement getStatement(Connection conn)
{
Statement st=null;
try
{
if(conn!=null)
st=conn.createStatement();
}
catch(SQLException e)
{
e.printStackTrace();
}
return st;
}
public static ResultSet getResultSet(Statement st,String sql)
{
ResultSet rs=null;
try
{
if(st!=null)
rs=st.executeQuery(sql);
}
catch(SQLException e)
{
e.printStackTrace();
}
return rs;
}
public static ResultSet getResultSet(Connection conn,String sql)
{
ResultSet rs=null;
Statement st=null;
try
{
if(conn!=null)
{
st=conn.createStatement();
rs=getResultSet(st,sql);
}
}
catch(SQLException e)
{
e.printStackTrace();
}
return rs;
}
public static void close(Connection conn)
{
try
{
if(conn!=null)
{
conn.close();
conn=null;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public static void close(Statement st)
{
try
{
if(st!=null)
{
st.close();
st=null;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public static void close(ResultSet rs)
{
try
{
if(rs!=null)
{
rs.close();
rs=null;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -