package test;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class PressTest { public static void main(String[] args) throws LogException {
for (int i=0;i<2000;i++)
{
    String driver = "oracle.jdbc.driver.OracleDriver";
    String strUrl= "jdbc:oracle:thin:@"+"localhost"+":1521:"+"HWDB";
    Connection conn = null;
    Statement stmt=null;
try
{
    Class.forName(driver);
    conn =  DriverManager.getConnection(strUrl, "HWEMS", "888");
    stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO presss_test VALUES ('XIAOXU',"+i+",'GUANGZHOU')");
}
catch(Exception e)
{
throw new RuntimeException(e);
}
finally
{   
try
{
stmt.close();
conn.close();
conn=null;
stmt=null;
}
catch(SQLException e)
{
throw new RuntimeException(e);
}
}

}
}}
这是我的源代码,目点是向数据库插入大量数据,检测其性能,是否有内存泄漏,后来发现如果i小于1000的话,程序正常运行,如果大于2000则出现java.lang.NullPointerException异常,
大家帮我看看什么问题,一般对数据库进行压力测试怎么测试,内存泄漏怎么测试?谢谢!

解决方案 »

  1.   

    for   (int   i=0;i <2000;i++) 

            String   driver   =   "oracle.jdbc.driver.OracleDriver"; 
            String   strUrl=   "jdbc:oracle:thin:@"+"localhost"+":1521:"+"HWDB"; 
            Connection   conn   =   null; 
            Statement   stmt=null; 这种链接是重型武器不能放到for循环里面搞的用spring 的JDBC模板做吧,pool缓存连接池,起1000个线程并发插入