java连接MySql数据库!
package com.roytel.rtccp.util;
import java.sql.*;
public class DBManager {
//用户名
private String user = "";
//密码
private String password = "";
//主机
private String host = "";
//数据库名字
private String database = "";
/*
private String url="jdbc:mysql://"+host+"/"+"useUnicode=true&characterEncoding=GB2312";
*/
private String url ="";
private Connection con = null;
Statement stmt;
/**
* 根据主机、数据库名称、数据库用户名、数据库用户密码取得连接。
* @param host String
* @param database String
* @param user String
* @param password String
*/
public DBManager(String host, String database, String user, String password) {
this.host = host;
this.database = database;
this.user = user;
this.password = password;
//显示中文
this.url = "jdbc:mysql://" + host + "/" + database +
"?useUnicode=true&characterEncoding=GB2312";
try {
Class.forName("org.gjt.mm.mysql.Driver");
}
catch (ClassNotFoundException e) {
System.err.println("class not found:" + e.getMessage());
}
try {
con = DriverManager.getConnection(this.url, this.user, this.password);
- 相关文章
- 最新文章
- JSP、Servlet中的相对路径和绝对..[12-04]
- Mysql的子类,专门验证登录 PassS..[12-04]
- Eclipse主要插件Lomboz介绍(4)_C..[12-04]
- java的io简单应用 选择自 FrankT..[12-04]
- 怎么使用DBMS存储过程[12-04]
- 开发工工具配置笔记——Jcreator..[12-04]
