title: JUNIT test case for connection with database
body: <p><strong>This is the code which im testing for JDBC connection</strong></p>
  
  <pre><code>package com.sybase;
  
  
  public class SybaseDBConnection {
  
      public static Properties prop = null;
  
  
      public static Connection getConnection(String databaseType) {
  
          Connection conn = null;
          // Properties prop = null;
          String database = null;
          String driver = null;
          String url = null;
          String user = null;
          String password = null;
  
          try {
              // prop = new Properties();
              // prop.load(SybaseDBConnection.class.getClassLoader()
              // .getResourceAsStream("com/properties/sybase.properties"));
  
              database = prop.getProperty("sybase." + databaseType
                      + ".databaseName");
              driver = prop.getProperty("sybase." + databaseType
                      + ".driverClassName");
              url = prop.getProperty("sybase." + databaseType + ".url");
              user = prop.getProperty("sybase." + databaseType + ".username");
              password = prop.getProperty("sybase." + databaseType + ".password");
  
              // String dbConUrl =
              // "jdbc:datadirect:sqlserver://nt64sl2003a.americas.progress.comsql2008;Port=1433;DatabaseName=test;User=test;Password=test;EnableBulkLoad=true;BulkLoadBatchSize="
              // + JDBC_BATCH_SIZE;
  
              String dbConUrl = url + SEMI_COLLAN + "DatabaseName=" + database
                      + SEMI_COLLAN + "User=" + user + SEMI_COLLAN + "Password="
                      + password + SEMI_COLLAN + "EnableBulkLoad=true"
                      + SEMI_COLLAN + "BulkLoadBatchSize=" + JDBC_BATCH_SIZE;
  
              System.out.println("The URL is : " + dbConUrl);
  
              SybDriver sybDriver = (SybDriver) Class.forName(driver)
                      .newInstance();
              sybDriver.setVersion(com.sybase.jdbcx.SybDriver.VERSION_6);
              DriverManager.registerDriver(sybDriver);
              conn = DriverManager.getConnection(dbConUrl);
          } catch (SQLException e) {
              System.err.println("Exception occured : SQLException : "
                      + e.getMessage());
              e.printStackTrace();
          } catch (InstantiationException e) {
              System.err.println("Exception occured : InstantiationException : "
                      + e.getMessage());
              e.printStackTrace();
          } catch (IllegalAccessException e) {
              System.err.println("Exception occured : IllegalAccessException : "
                      + e.getMessage());
              e.printStackTrace();
          } catch (ClassNotFoundException e) {
              System.err.println("Exception occured : ClassNotFoundException : "
                      + e.getMessage());
              e.printStackTrace();
          }
  
          return conn;
      }
  
      public static void closeConnection(Connection conn) {
          try {
              if (null != conn) {
                  conn.close();
                  conn = null;
              }
          } catch (SQLException e) {
              e.printStackTrace();
  
          }
      }
  
      public static void closeResultset(ResultSet rs) {
          try {
              if (null != rs) {
                  rs.close();
                  rs = null;
              }
          } catch (SQLException e) {
              e.printStackTrace();
  
          }
      }
  
      public static void closePreparedStatement(PreparedStatement pstmt) {
          try {
              if (null != pstmt) {
                  pstmt.close();
                  pstmt = null;
              }
          } catch (SQLException e) {
              e.printStackTrace();
  
          }
      }
  
      public static void closeStatement(Statement stmt) {
          try {
              if (null != stmt) {
                  stmt.close();
                  stmt = null;
              }
          } catch (SQLException e) {
              e.printStackTrace();
  
          }
      }
  
      public static String getProperty(String property) {
          return prop.getProperty(property);
      }
  
      public static void main(String args[]) {
          SybaseDBConnection.getConnection("ase");
      }
  
  }
  </code></pre>
  
  <p><strong>I have written this test Case</strong></p>
  
  <pre><code>public class SybaseStatementTest {
  
      Connection conn;
      Statement stmt;
  
      // Setup methods
      @BeforeClass
      public void beforeClass() {
          conn = null;
          stmt = null;
      }
  
      // clean up method
      @AfterClass
      public void releaseResource() {
          if (stmt != null) {
              SybaseDBConnection.closeStatement(stmt);
          }
          if (conn != null) {
              SybaseDBConnection.closeConnection(conn);
          }
      }
  
  
      // Test case to check close statement using ASE database
      @Before
      public void openConnBeforerStmtTestASE() throws SQLException {
          conn = SybaseDBConnection.getConnection("ase");
          stmt = conn.createStatement();
      }
  
      @After
      public void closeConnAfterStmtTestASE() {
          if (conn != null) {
              SybaseDBConnection.closeConnection(conn);
          }
      }
  
      @Test
      public void testCloseStatementASE() {
          SybaseDBConnection.closeStatement(stmt);
          Assert.assertNull("Error occured", stmt);
      }
  }
  </code></pre>
  
  <p><strong>I am getting an Initialization error(@BeforeClass should be static) when I run this Junit test case.
  Please can you help?</strong> </p>