⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbconnection.java

📁 这是java的源代码,感觉上是挺不错的哦,要下载赶快来哦,有附加数据库的哦
💻 JAVA
字号:
package ptu.db;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBConnection {
	//创建连接,指定数据库的名字。注固定写法,没必要知道具体在系统里面是什么操作
	private static final String conURL = "jdbc:jtds:sqlserver://127.0.0.1:1433/ptstu;user=sa;password=sa";

	private static final String classInfo = "net.sourceforge.jtds.jdbc.Driver";

	//创建连接,如里连接失败则提示“请确认数据库是否加载“,如果成功则返回一个连接
	public static Connection getConnection() throws Exception {
		Connection con = null;
		try {
			Class.forName(classInfo);
		} catch (ClassNotFoundException ex) {
			throw new SQLException("请确认数据库是否加载");
		}
		con = java.sql.DriverManager.getConnection(conURL);
		return con;
	}
//关闭连接
	public static void closeConnection(Connection con) {
		if (con != null) {
			try {
				con.close();
				con = null;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
//关闭邮差
	public static void closeStatement(Statement statement) {
		if (statement != null) {
			try {
				statement.close();
				statement = null;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}// Dateset
//关闭结果集
	public static void closeResultSet(ResultSet rs) {
		if (rs != null) {
			try {
				rs.close();
				rs = null;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -