sfs2x 连接 mysql

  <databaseManager active="true">
    <driverName>com.mysql.jdbc.Driver</driverName>
    <connectionString>jdbc:mysql://127.0.0.1:7878/test</connectionString>
    <userName>root</userName>
    <password>kwgkwg</password>
    
    <testSql></testSql>
    <maxActiveConnections>10</maxActiveConnections>
    <maxIdleConnections>10</maxIdleConnections>
    <exhaustedPoolAction>FAIL</exhaustedPoolAction>
    <blockTime>3000</blockTime>
  </databaseManager>

1。修改你的 zone 配置文件 ... 在最后 </zone> 里加入上面 xml

2。在mysql官方网下载 java 驱动 5.1.20。然后放在你的sfs扩展工程,,,或者放在 你的jdk目录.

3。别忘了在 sfs里也放一份 SFS2X\lib\ 

void initMysql() {
        trace("\n++++++++++++++++++++++mysql++++++++++++++++++++++++\n");

        String sql = "SELECT * FROM user_base";
        //ISFSArray res = dbManager.executeQuery(sql);

        IDBManager dbManager = getParentZone().getDBManager();
        try {
            Connection conn = (Connection) dbManager.getConnection();
            Statement stmt = conn.createStatement() ;    // 实例化Statement对象        
            
            //stmt.executeUpdate(sql) ;        // 执行数据库更新操作 
        
            PreparedStatement ppst =conn.prepareStatement("INSERT INTO user_base(user) values(?)") ;
            for(int i=1;i<2500;i++)
            {
                ppst.setString(1, "user");
                //ppst.setInt(2, i);
                //ppst.setDate(3,new java.sql.Date(new java.util.Date().getTime())) ;
                ppst.addBatch();
            }
            //ppst.addBatch("truncate table user");
            int t[] =ppst.executeBatch();
            //System.out.println(t.length);
            
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next())
            {
                String str = rs.getString("user");
                trace(str);
            }        
            
            ppst.close();
            stmt.close();
        } catch (SQLException e) {
            trace(ExtensionLogLevel.WARN, "SQL Failed: " + e.toString());
        }
    }

遇到的问题,,,出错 passwd default value ...........

重新安装mysql 就可以了

posted @ 2012-05-21 13:48  solq  阅读(1311)  评论(0编辑  收藏  举报