connectionmanager.java~1~
来自「我做的第一个java MIS项目」· JAVA~1~ 代码 · 共 58 行
JAVA~1~
58 行
package server.dao;
import java.sql.*;
public class Connactionmanager {
//四种方法:得到连接、关闭连接、关闭诉说、关闭结果集
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 + =
减小字号Ctrl + -
显示快捷键?