String driver = props.getProperty("jdbc.dest.driver"); String url = props.getProperty("jdbc.dest.url"); String user = props.getProperty("jdbc.dest.username"); String pass = props.getProperty("jdbc.dest.password"); user = StringUtils.isNullOrEmpty(user) ? null : user; pass = StringUtils.isNullOrEmpty(pass) ? null : pass; Class.forName(driver); Connection con; if ((user == null) && (pass == null)) { con = DriverManager.getConnection(url); } else { con = DriverManager.getConnection(url, user, pass); } PreparedStatement stmtTestConnection = con.prepareStatement("select dataid ,name from DTREE where dataid = ?"); stmtTestConnection.setInt(1, 2000); ResultSet rs = stmtTestConnection.executeQuery(); while(rs.next()) { System.out.printf("dataid: %s, name: %s%n", rs.getInt(1), rs.getString(2)); }