Pacific-Design.com

    
Home Index

1. Java

2. Snippets

+ Choices

+ DateTime

+ HttpURLConnection

+ Random

+ ResultSet

+ TimeZones

+ if statement

Java / Snippets /

Java Debug Code


   public void debug(String content) {
        try {
            String filename = "src/debug/debug00.txt";
            FileWriter fw = new FileWriter(filename, true);
            System.out.println(content);
            fw.write(content + "\n");
            fw.close();
        } catch (IOException ioe) {
            System.err.println("IOException: " + ioe.getMessage());
        }

    }

Horizonal Line


    public void line(int i) {
        char[] chars = new char[i];
        Arrays.fill(chars, '-');
        System.out.println(String.valueOf(chars));
    }

Sleep


  public void sleep(int i) {
        try {
            Thread.sleep(i);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }

Try Catch Class, Method, Line info


 try {
     statement = connection.createStatement();
     total = statement.executeUpdate(insertQuery);

 } catch (SQLException ex) {
     
     System.err.println("SQLException: " 
             + Thread.currentThread().getStackTrace()[2].getClassName()  + "\n"
             + Thread.currentThread().getStackTrace()[2].getMethodName() + ":"                    
             + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n"                                        
             + ex.getMessage() + "\n");            
 }