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

📄 dbutil.java

📁 公告管理系统。能够进行公告的发布
💻 JAVA
字号:
package nm;

import java.sql.*;

/**
 * <strong>DBUtil </strong> is a utility class to create a connection to our
 * sample database.
 */
public class DBUtil {
	static String driverName = "org.gjt.mm.mysql.Driver";

	static String dbUrl = "jdbc:mysql://localhost:3306/noticemanager?useUnicode=true&characterEncoding=gb2312";

	static String dbUser = "root";

	static String dbPwd = "root";

	public DBUtil() {
	}

	public static java.sql.Connection connectToDB(
			) throws Exception {
		Class.forName(driverName).newInstance();
		Connection con = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
		return con;
	}

//	public static void main(String args[]) {
////		try {
////			String name = "oracle.jdbc.driver.OracleDriver";
////			String url = "jdbc:oracle:thin:@localhost:1521:kevin";
////			Class.forName(name).newInstance();
////			Connection con = DriverManager.getConnection(url, "kevin", "kevin");
////			System.out.println("杩炴帴Oracle 9i鎴愬姛!");
////			con.close();
////		} catch (Exception e) {
////			e.printStackTrace();
////		}
//		
////		try {
////			String name = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
////			String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JavaWeb";
////			Class.forName(name).newInstance();
////			Connection con = DriverManager.getConnection(url, "sa", "sa");
////			System.out.println("杩炴帴SQL Server 2000鎴愬姛!");
////			con.close();
////		} catch (Exception e) {
////			e.printStackTrace();
////		}
//		
//		try {
//			String name = "org.gjt.mm.mysql.Driver";
//			String url = "jdbc:mysql://localhost:3306/noticemanager?useUnicode=true&characterEncoding=gb2312";
//			Class.forName(name).newInstance();
//			Connection con = DriverManager.getConnection(url, "root", "root");
//			
//			System.out.println("杩炴帴MySQL 5.0.18鎴愬姛!(椹卞姩3.1.8)");
//			
//			PreparedStatement pStmt = null;
//			ResultSet rs = null;
//
//			int id = 0;
//			String title = null;
//			String content = null;
//			
//			String strSql = new String("SELECT * FROM notice");
//			try {
//				pStmt = con.prepareStatement(strSql,
//						ResultSet.TYPE_SCROLL_INSENSITIVE,
//						ResultSet.CONCUR_READ_ONLY);
//				rs = pStmt.executeQuery();
//				
//				if(rs.next()) {
//					id = Integer.parseInt(rs.getString("ID"));
//					
//					title = rs.getString("Title");
//					title = new String(title.getBytes("ISO-8859-1"), "GB2312");
//					
//					content = rs.getString("Content");
//					content = new String(content.getBytes("ISO-8859-1"), "GB2312");
//					
//					System.out.println(id);
//					System.out.println(title);
//					System.out.println(content);
//				}
//			} finally {
//				try {
//					rs.close();
//					pStmt.close();
//					con.close();
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
}

⌨️ 快捷键说明

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