I'm trying to initialize and declare variable in if-else condition in JAVA, but it is not executing, can someone please help me in below code?
This is the method, which I'm calling from main method. But it's not executing the initialization under if condition and failing.
public static void getData(String funct) {
try {
if ("lob".equals(funct)) {
String sql1= String.format("select distinct lob_name from BPUSH_lobs order by lob_name");
}
else {
String sql1= String.format("select distinct env_type from BPUSH_environments order by env_type");
}
Connection conn=DriverManager.getConnection
("jdbc:oracle:thin:@172.23.240.41:1521:BCTOOLS","AMCOPR","AMCOPR");
Statement stmt = conn.createStatement();
ResultSet rst;
System.out.println(funct);
rst = stmt.executeQuery(sql1);
while (rst.next()) {
String lobName = rst.getString("lob_name");
System.out.format("%s\n",lobName);
}
conn.close();
}
catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
PLEASE HELP :) Thanks,
Aucun commentaire:
Enregistrer un commentaire