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

📄 dbutil.java

📁 网上考试系统文件版
💻 JAVA
字号:
/*
 * Created on 2006-4-6
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package todb;
import java.sql.*;

/**
 * @author admin
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class DbUtil {
	static String driverName = "org.gjt.mm.mysql.Driver";
	static String dbUrl = "jdbc:mysql://";
	static String mysqlUser = "root"; //数据库用户名
	static String mysqlPsw = "webexam"; //数据库密码

	public DbUtil() {
	}

	public static java.sql.Connection connectToDb(
		String hostName,
		String databaseName)
		throws Exception {
		Connection connection = null;
		String connName =
			dbUrl
				+ hostName
				+ ":3306"
				+ "/"
				+ databaseName
				+ "?user="
				+ mysqlUser
				+ "&password="
				+ mysqlPsw;
		Class.forName(driverName).newInstance();
		connection = DriverManager.getConnection(connName);
		return connection;
	}

	public static java.sql.Connection connectToDb(String databaseName)
		throws Exception {
		return (connectToDb("localhost", databaseName));
	}

	public static java.sql.Connection connectToDb() throws Exception {
		return (connectToDb("localhost", "onlineexam"));
	}

}

⌨️ 快捷键说明

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