dbconnection.java

来自「中国移动管理系统」· Java 代码 · 共 73 行

JAVA
73
字号
//package com.chinamobile.db;
//
//import java.sql.*;
//
//public class DBConnection {
//	private Connection conn;
//	private Statement stmt;
//	private ResultSet rs;
//
//	public DBConnection() {
//		try {
//			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	public Connection getConnection() {
//		try {
//			conn = DriverManager.getConnection(
//					"jdbc:sqlserver://localhost:1049;DatabaseName=ChinaMobile ",
//					"sa", "123");
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return conn;
//	}
//
//	public void closeAll() {
//		try {
//			if (rs != null) {
//				rs.close();
//			}
//			if (stmt != null) {
//				stmt.close();
//			}
//			if (conn != null) {
//				conn.close();
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	public ResultSet executeQuery(String sql) throws SQLException {
//		conn = getConnection();
//		stmt = conn.createStatement();
//		rs = stmt.executeQuery(sql);
//		return rs;
//	}
//
//	public int executeUpdate(String sql) throws SQLException {
//		conn = getConnection();
//		stmt = conn.createStatement();
//		int i = stmt.executeUpdate(sql);
//		return i;
//	}
//
//	public int executeUpdate(String[] sql) throws SQLException {
//		conn = getConnection();
//		stmt = conn.createStatement();
//		conn.setAutoCommit(false);
//		int count = 0;
//		for (int i = 0; i < sql.length; i++) {
//			System.out.println(sql[i]);
//			count += stmt.executeUpdate(sql[i]);
//		}
//		conn.commit();
//		conn.setAutoCommit(true);
//		return count;
//	}
//}

⌨️ 快捷键说明

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