title: Unable to connect to database based on property file
body: <p>Hi I'm new in java/jsp developing.</p>
  
  <p>I'm trying to connect to database depending on parameter that jsp file receives from previous page.
  My program works if i connect to single DB like</p>
  
  <pre><code> try {
          InputStream in = getServletContext().getResourceAsStream("/WEB-INF/db.properties");
          properties.load(in);
          connString = properties.getProperty("db_conn").toString();
          connUser = properties.getProperty("db_user").toString();
          connPass = properties.getProperty("db_pass").toString();
          bPath = properties.getProperty("exec_path").toString();
          in.close();
        } catch (IOException ex) {
          System.out.println(ex);
        }
  </code></pre>
  
  <p>and db.properties file contains</p>
  
  <pre><code>      db_conn=jdbc:oracle:thin:@33.333.3.33:3333:DKSE1
        db_user=guest
        db_pass=guestpw
  </code></pre>
  
  <p>My attempt:</p>
  
  <pre><code> String userinfo = request.getParameter("userinfo");
   try {
          InputStream in = getServletContext().getResourceAsStream("/WEB-INF/db.properties");
          properties.load(in);
          db_conn = userinfo + "_conn";
          db_user = userinfo + "_user";
          db_pass = userinfo + "_pass";
          connString = properties.getProperty(db_conn).toString();
          connUser = properties.getProperty(db_user).toString();
          connPass = properties.getProperty(db_pass).toString();
          bPath = properties.getProperty("exec_path").toString();
          in.close();
        } catch (IOException ex) {
          System.out.println(ex);
        }
  
        try {
          // --- Required database stuff ---
          DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
          Connection conn = DriverManager.getConnection(connString, connUser, connPass);
          Statement stmt = conn.createStatement();
          More codes....
         }
  </code></pre>
  
  <p>db.properties</p>
  
  <pre><code>       guest_conn=jdbc:oracle:thin:@33.333.3.33:3333:DKSE1
         guest_user=guest
         guest_pass=guestpw
  
         user_conn=jdbc:oracle:thin@11.222.3.33:4444:ESMZ1
         user_user=user
         user_pass=upw1
  
         user1_conn=jdbc:oracle:thin@11.11.1.11:1111:GEPD1
         user1_user=user1
         user1_pass=upw1 
  
         batch_exec_path = ${SERVER_DIR}
  </code></pre>
  
  <p>Stacktrace</p>
  
  <pre><code>Nov 30, 2012 9:03:55 AM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [jsp] in context with path [/dashboard] threw exception [An exception occurred processing JSP page /alpharunBatch.jsp at line 106
  
  103:             db_conn = userinfo + "_conn";
  104:             db_user = userinfo + "_user";
  105:             db_pass = userinfo + "_pass";
  106:             connString = properties.getProperty(db_conn).toString();
  107:             connUser = properties.getProperty(db_user).toString();
  108:             connPass = properties.getProperty(db_pass).toString();
  109:             bPath = properties.getProperty("exec_path").toString();
  
  
  Stacktrace:] with root cause
  java.lang.NullPointerException
      at org.apache.jsp.alpharunBatch_jsp._jspService(alpharun_jsp.java:192)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>Am i doing something fundamentally wrong?
  Thanks for your help!</p>