📄 connectionmanager.java
字号:
package server.dao;
import java.sql.*;
public class Connectionmanager {
//四种方法:得到连接、关闭连接、关闭诉说、关闭结果集
private Connection connectionobj;
//得到连接
public Connection getconnection ()
{
//数据源
try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException ex1) {}
//建立连接
try
{connectionobj=DriverManager.getConnection("JDBC:ODBC:MRS");}
catch (SQLException ex) {System.out.println("建立连接失败!");}
//返回一个连接
return connectionobj;
}
//关闭连接
public void closeconnection (Connection willcloseconnection)
{
//关闭连接
try
{
if (willcloseconnection !=null &&!willcloseconnection.isClosed())
{willcloseconnection.close();}
}
catch (SQLException ex) {System.out.println("关闭连接失败!");}
}
//关闭诉说
public void closestatement (Statement willclosestatement)
{
//关闭诉说
try {
if (willclosestatement!=null)
{willclosestatement.close();}
}
catch (SQLException ex) {System.out.println("关闭诉说失败!");}
}
//关闭结果集
public void closeresultset (ResultSet willcloseresultset)
{
//关闭结果集
try {
if (willcloseresultset!=null)
{willcloseresultset.close();}
}
catch (SQLException ex) {System.out.println("关闭结果集失败!");}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -