日期:2014-05-16  浏览次数:20705 次

别人写的一个mysql数据处理的javabean
数据库处理的javabean:(我厚道吧,这都贴出来了)

mysqlmeans.java(位置:MySQL/mysqlmeans.java):

package MySQL;
import java.sql.*;
/**
*
* @author lucifer
*/

public class mysqlmeans {
     Connection con;
    String username = "";
    String password = "";
     String server = "";
     String dbname = "";
     public void setProperties(String serv,String db,String name,String pass){
          server = serv;
          dbname = db;
          username = name;
          password = pass;
     }

     public void setUserName(String username){
          this.username = username;
     }
     public String getUserName(){
          return username;
     }

     public void setPassword(String password){
          this.password = password;
     }
     public String getPassword(){
          return password;
     }

     public void setServer(String server){
          this.server = server;
     }
     public String getServer(){
          return server;
     }

     public void setDataBase(String daname){
          this.dbname = daname;
     }
     public String getDataBase(){
          return dbname;
     }

     public Connection getConnection(){
        try{
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection
                       ("jdbc:mysql://"+server+"/"+dbname+"?user="+username+"&password="+password, username, password);
            return con;
        }catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public void exeUpdate(String sql){
        Connection upCon = getConnection();
        try{
            Statement stmt = upCon.createStatement();
            stmt.executeUpdate(sql);
            stmt.close();
            upCon.close();
        }catch(Excep