http://jxhandyanxue.uu1001.com
这里面能够找到你想要的

解决方案 »

  1.   

    那上边没有呀
    我想要用Java类写的  这样就可以连接任何数据库 
    还可以重用
      

  2.   

    package com.fenye;import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;public class ConnectionMessage {
    private Connection conn = null;
    public ConnectionMessage(){
    this("root","admin");
    }

    public ConnectionMessage(String username,String password){
    String className = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/test";

    try {
    Class.forName(className);
    conn = DriverManager.getConnection(url,username,password);
    System.out.println("数据库连接成功");
    } catch (ClassNotFoundException e) {
    System.out.println("数据库连接失败");
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SQLException e) {
    System.out.println("数据库连接失败");
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    public Connection getConnection(){
    return conn;
    }

    public static void close(ResultSet rs,Statement st,PreparedStatement ps,CallableStatement cs,Connection conn){
    try {
    if(rs!=null){
    rs.close();
    }
    if(st!=null){
    st.close();
    }
    if(ps!=null){
    ps.close();
    }
    if(cs!=null){
    cs.close();
    }
    if(conn!=null){
    conn.close();
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }}这个是连接mysql的连接类~
    不过我不是大哥,嘎嘎