⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sql.java

📁 这是一个基于计算网格的web service。它用java编写。一旦安装完成
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * SQL.java * * Created on April 15, 2005, 12:16 PM */package jwsgrid.resourcemanager.priv;import java.sql.*;/** * * @author sean */public class Sql {      ////////////////////////////////////////////////////////////////////////////    // public classes    //         public static class CpuLoadStats    {        private String wsAddr;        private Timestamp updateTs;        private int updateCount;        private int total;                public CpuLoadStats(                 String wsAddr,                int updateCount,                int total )        {            this.wsAddr = wsAddr;            this.updateTs = updateTs;            this.updateCount = updateCount;            this.total = total;        }                public String getWsAddr() { return wsAddr; }        public int getUpdateCount() { return updateCount; }        public int getTotal() { return total; }    }        /*    public static class ConfigResult    {        private int jobHostUpdateFreq = 0;                public ConfigResult( int jobHostUpdateFreq )        {            this.jobHostUpdateFreq = jobHostUpdateFreq;        }                public int getJobHostUpdateFreq() { return jobHostUpdateFreq; }            }     */        ////////////////////////////////////////////////////////////////////////////    // public attributes    //     public final static String DB_SCHEMA = "gridresmgr";    public final static String DB_USER = "gridresmgr";        public final static String TBL_JOBHOST_STATS = "jobhost_stats_cpu";    public final static String TBL_CFG = "config";        public final static String LOG_MAXENTRIES_STR = "100";    public final static int LOG_MAXENTRIES = 100;              ////////////////////////////////////////////////////////////////////////////    // private attributes    //            private static final String MYSQL_DRV = "com.mysql.jdbc.Driver";            private final static String COL_CFG_ID = "id";    private final static String COL_CFG_JOBHOST_UPDFREQ = "jobhost_updatefreq";        private final static String COL_JHSTATS_WSADDR = "ws_addr";    private final static String COL_JHSTATS_CPU_UPDATECOUNT = "load_update_count";    private final static String COL_JHSTATS_CPU_LOADTOTAL = "load_total";            private static String connStr = null;            ////////////////////////////////////////////////////////////////////////////    // public methods    //         public static String createTableInitScript()     {        String initScript = "";                initScript +=                "CREATE TABLE `" + DB_SCHEMA + "`.`" + TBL_JOBHOST_STATS + "` (\n" +                "`" + COL_JHSTATS_WSADDR + "` VARCHAR(255)  NOT NULL,\n" +                "`" + COL_JHSTATS_CPU_UPDATECOUNT + "` INT(11)  NOT NULL,\n" +                "`" + COL_JHSTATS_CPU_LOADTOTAL + "` INT(11)  NOT NULL,\n" +                "PRIMARY KEY(`" + COL_JHSTATS_WSADDR + "`)\n" +                ")\n" +                "TYPE = MYISAM;\n";                 /*        initScript +=                "CREATE TABLE `" + DB_SCHEMA + "`.`" + TBL_CFG + "` (\n" +                "`" + COL_CFG_ID + "` INT(11)  NOT NULL,\n" +                "`" + COL_CFG_JOBHOST_UPDFREQ + "` INT(11)  NOT NULL,\n" +                "PRIMARY KEY(`" + COL_CFG_ID + "`)\n" +                ")\n" +                "TYPE = MYISAM;\n";         */                return initScript;    }        public static Connection getConnection() throws SQLException, Exception     {        Connection conn = null;                if ( connStr == null )         {            throw new SQLException( "connection parameters have not been set" );        }                try         {            conn = DriverManager.getConnection( connStr );                     } catch( SQLException sqle ) {            throw sqle;        }                return conn;    }             /** set connection parameters */    public static void setConnectionParams(            String host,            String port,            String pass )     {        if ( host.startsWith( "http://") )         {            String tmp = "http://";            host = host.substring( tmp.length(), host.length() );        }                connStr =  "jdbc:mysql:/";        connStr += "/" + host;        connStr += ":" + port;        connStr += "/" + DB_SCHEMA ;             connStr += "?user=" + DB_USER;        connStr += "&password=" + pass;               }          public static void loadDriver() throws Exception     {        try         {            Class.forName( MYSQL_DRV ).newInstance();                     } catch ( Exception ex ) {            throw ex;        }    }        public static void loadDriver( String drv ) throws Exception     {        try         {             Class.forName( drv ).newInstance();                     } catch ( Exception ex ) {             throw ex;                     }      }        /*    public static void deleteConfig( Connection conn )    throws SQLException, Exception     {        Statement stmt = null;                 try         {            stmt = conn.createStatement();            stmt.execute( "DELETE FROM " + TBL_CFG );                    } catch ( SQLException sqle ) {            throw sqle;                    } catch ( Exception ex ) {            throw ex;                    } finally {            try             {                if( stmt != null )                 {                    stmt.close();                    stmt = null;                }                             } catch ( Exception ex ) {}                    }                                }     */        public static void deleteJobHostStats( Connection conn )    throws SQLException, Exception     {        Statement stmt = null;                 try         {            stmt = conn.createStatement();            stmt.execute( "DELETE FROM " + TBL_JOBHOST_STATS );                    } catch ( SQLException sqle ) {            throw sqle;                    } catch ( Exception ex ) {            throw ex;                    } finally {            try             {                if( stmt != null )                 {                    stmt.close();                    stmt = null;                }                             } catch ( Exception ex ) {}                    }                                }            /*    public static ConfigResult getConfig( Connection conn )     throws SQLException, Exception     {        Statement stmt = null;         ResultSet rs = null;        String sqlstr = null;         int rowCount = 0;                try         {            stmt = conn.createStatement();                        sqlstr = "SELECT * FROM " + TBL_CFG;                        if ( !stmt.execute( sqlstr ) )             {                throw new SQLException(                         "SELECT * failed on table '" + TBL_CFG + "'" );            }                        rs = stmt.getResultSet();            if ( rs.next() )             {                return new ConfigResult( rs.getInt( COL_CFG_JOBHOST_UPDFREQ ) );                         }                                                else            {                return null;            }                    } catch ( SQLException sqle ) {            throw sqle;                    } catch ( Exception ex ) {            throw ex;                    } finally {            try             {                if( rs != null )                 {                    rs.close();                    rs = null;                }                            } catch ( Exception ex ) {}                            try             {                if( stmt != null )                 {                    stmt.close();                    stmt = null;                }                             } catch ( Exception ex ) {}                    }                             }     */        /*    public static void setConfig( Connection conn, int jobHostUpdateFreq )     throws SQLException, Exception     {        Statement stmt = null;         ResultSet rs = null;        String sqlstr = null;         int rowCount = 0;                try         {            stmt = conn.createStatement();                        sqlstr = "SELECT * FROM " + TBL_CFG;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -