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

📄 db.java

📁 《JSP通用模块及典型系统开发实例导航》源代码
💻 JAVA
字号:
package com.wxpn.tutorial.db;

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.xml.parsers.*;

import org.w3c.dom.*;

/**
 * 描述: 数据库连接类 Copyright (c) 2005-2008 Wang Xining
 * 
 * @author 王夕宁
 * @version 1.0
 */

public class DB {
	static String driver = "org.gjt.mm.mysql.Driver";

	static String server = "jdbc:mysql://127.0.0.1/learnjsp?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8";

	static String dbuser = "root";

	static String dbpassword = "";

	static int minconn = 5;

	static int maxconn = 20;

	static double maxconntime = 0.1D;

	static ConnectionPool p = null;

	/**
	 * Create a connectionpool
	 */
	public static ConnectionPool getConnPool() {
		try {
			if (p == null) {
				p = new ConnectionPool(driver, server, dbuser, dbpassword,
						minconn, maxconn, maxconntime);
			}
			return p;
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}

	public static void main(String[] args) {
		ConnectionPool connPool = DB.getConnPool();
		Connection conn = connPool.getConnection();
		Statement stmt = null;
		ResultSet rs = null;

		try {
			int nextMessageid = 0;
			String relative_path = null;

			String sql = "select * from userinfo";
			stmt = conn.createStatement();
			// stmt.addBatch(sql);
			// sql = "insert into
			// mms_user(messageid,emailid,messagename,sender,coypto,bcc,sendtime,size,totalnumber,priority,remark,content)
			// values('7','1','Fw: 中文标识
			// 57567567','<wxn1@localhost>','<12121@localhost>','','Sun Oct 03
			// 14:30:13 CST 2004','114421','2','3','','')";
			sql = new String(sql.getBytes("gb2312"), "8859_1");
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				System.out.println(rs.getString("UserName"));
			}
		} catch (SQLException sqlExc) {
			sqlExc.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (stmt != null) {
					stmt.close();
				}
				connPool.freeConnection(conn);
				System.out.println("free connection!");
			} catch (SQLException sqlExc) {
				sqlExc.printStackTrace();
			}

		}
	}

}

⌨️ 快捷键说明

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