run as -> java application
debug as -> java application

解决方案 »

  1.   

    建立testcase,直接以application的方式运行该测试程序
      

  2.   

    当然可以了,servlet调用和java调用是一样的
      

  3.   

    是这样的,比如在jsp中
    InitialContext ctx=new InitialContext();
    ds=(DataSource)ctx.lookup("java:comp/env/jdbc/test");
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    ....
    执行的时候没问题,但是如果我在javabean里面写同样,就会报错:javax.naming.NoInitialContextException: 我想知道的就是tomcat的InitialContext的properties怎么写
      

  4.   

    你是想获得connection是吧
    InputStream is =getClass().getResourceAsStream("/db.properties");
    Properties dbProps = new Properties();
    try {
        dbProps.load(is);
    } catch (Exception e) {
        System.err.println("Can't read the properties file. ");
        return;
    }
    URL =dbProps.getProperty("URL","jdbc:postgresql://127.0.0.1:5432/mydb");
    String user = dbProps.getProperty("user", "test");
    String password = dbProps.getProperty("password", "test");
    String driverClasses = props.getProperty("drivers");
    Driver driver =(Driver) Class.forName(driverClasses).newInstance();
    Connection con = DriverManager.getConnection(URL);
    Statement stmt = conn.createStatement();
    ........