[今天翻硬盘的workspace发现一个Java Socket实现多人聊天室的源码,不记得是什么时候的事情了,貌似不是我写的。但写得还不错, 至少算个有模有样的聊天室工具。我简单的修
封装的DButil.java,负责数据库连接:
[Groovy入门教程kmyhy@126.com 2009-5-13一、groovy是什么简单地说,Groovy 是下一代的java语言,跟java一样,它也运行在 JVM 中。作为跑在JVM中的另一种语言,groovy语法
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ethan.util;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Administrator
*/
public class DBUtil {
private static final String url = "jdbc:mysql://localhost:3306/test";
private static final String username = "root";
private static final String password = "";
//private DBUtil dbUtil = null;
private DBUtil() {
}
static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(DBUtil.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static Connection getConn() {
try {
return DriverManager.getConnection(url,username,password);
} catch (SQLException ex) {
Logger.getLogger(DBUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public static PreparedStatement getPstmt(Connection conn, String sql) {
try {
return conn.prepareStatement(sql);
} catch (SQLException ex) {
Logger.getLogger(DBUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public static ResultSet getRs(PreparedStatement pstmt) {
try {
return pstmt.executeQuery();
} catch (SQLException ex) {
Logger.getLogger(DBUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public static void close(Connection conn,Statement stmt, ResultSet rs) {
if(conn!=null) {
try {
conn.close();
conn = null;
} catch (SQLException ex) {