For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Hello, I have 1400 records for which I have to use CASE condition for performing an operation in a table. Now, is there any simpler way to write CASE condition in a more compact way so that I don't have to write CASE condition 1400 times.
package com.test.dnsresolver; import java.io.BufferedReader; public class DnsResolver { private static final String urlString = "www.google.com"; private static final String resolvConf = "/etc/resolv.conf"; public static void main(String[] args) { int loopCounter = 0; while (true) { loopCounter++; try { Thread.sleep(1000); } catch (InterruptedException e) {} // Parse the current DNS server to be used in the config String nameserver = null; try { BufferedReader input = new BufferedReader(new FileReader(new File(resolvConf))); String currentLine = null; while (( currentLine = input.readLine()) != null){ // Take care of potential comments currentLine = currentLine.substring(0, currentLine.indexOf("#") == -1 ? currentLine.length() : currentLine.indexOf("#") ); if (currentLine.contains("nameserver")) { // It is the line we are looking for nameserver = currentLine; break; } } } catch (FileNotFoundException e) { System.out.println("Loop " + loopCounter + ": FileNotFoundException"); } catch (IOException e) { System.out.println("Loop " + loopCounter + ": IOException"); } if (nameserver == null) { // No "nameserver" line found System.out.println("Loop " + loopCounter + ": No nameserver found in configration file!"); continue; } // Trim it to just contain the IP address nameserver = (nameserver.replace("nameserver", "")).trim(); System.out.println("Loop " + loopCounter + ": Going to use DNS server " + nameserver); // At this point, we know which server to use, now perform the resolution Hashtable<String, String> env = new Hashtable<String, String>(); env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); env.put("java.naming.provider.url", "dns://" + nameserver); DirContext ictx; try { ictx = new InitialDirContext(env); Attributes attrs1 = ictx.getAttributes(urlString, new String[] {"A"}); System.out.println("Loop " + loopCounter + ": Manual resolution: +" + attrs1.get("a").get() + "+"); } catch (NamingException e) { System.out.println("Loop " + loopCounter + ": NamingException"); } } } }