Homepageseo.com
Login
登录[Login]
Reg
注册[Reg]
Member
会员[Member]
BBs
论坛[BBs]
logout
退出[Logout]
Search
搜索[Search]
Search For:        Advanced Search   
Guide: 搜索引擎优化 >> IT技术专栏 >> 编程语言 >> java连接MySql数据库!

java连接MySql数据库!

作者: 未知 来源: Blog 日期: 2006-12-04,08:55

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);

责任编辑: homepage 参与评论
免责申明: 本网转载内容均来自互联网,本网并不保证其内容的真实性。如果您认为本网站某部分的内容有侵权嫌疑,敬请立即通知我们,我们将在第一时间予以更改或删除。