Example usage for java.lang Exception printStackTrace

List of usage examples for java.lang Exception printStackTrace

Introduction

In this page you can find the example usage for java.lang Exception printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:WindowsLookAndFeelDemo.java

public static void main(String[] args) {
    try {/* w w w .  ja  v  a2 s . c  om*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception e) {
        e.printStackTrace();
    }
    JLabel label = new JLabel("Label");
    JTextField field = new JTextField("www.java2s.com!");
    JList list = new JList(new String[] { "A", "B", "C" });
    JScrollPane listPane = new JScrollPane(list);
    listPane.setPreferredSize(new Dimension(250, 100));

    JScrollPane treePane = new JScrollPane(new JTree());
    treePane.setPreferredSize(new Dimension(250, 100));
    JButton button = new JButton("Click me");

    JPanel cp = new JPanel();
    cp.add(label);
    cp.add(field);
    cp.add(listPane);
    cp.add(treePane);
    cp.add(button);

    JFrame frame = new JFrame();
    frame.setTitle("Windows Look and Feel Demo");
    frame.setPreferredSize(new Dimension(280, 300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(cp);
    frame.pack();
    frame.setVisible(true);

}

From source file:SelectRecordsUsingPreparedStatement.java

public static void main(String[] args) {
    ResultSet rs = null;//from   w  w  w.j  av a  2s . c o  m
    Connection conn = null;
    PreparedStatement pstmt = null;
    try {
        conn = getConnection();
        String query = "select deptno, deptname, deptloc from dept where deptno > ?";

        pstmt = conn.prepareStatement(query); // create a statement
        pstmt.setInt(1, 1001); // set input parameter
        rs = pstmt.executeQuery();
        // extract data from the ResultSet
        while (rs.next()) {
            int dbDeptNumber = rs.getInt(1);
            String dbDeptName = rs.getString(2);
            String dbDeptLocation = rs.getString(3);
            System.out.println(dbDeptNumber + "\t" + dbDeptName + "\t" + dbDeptLocation);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            rs.close();
            pstmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:SerialDemo.java

static public void main(String[] args) {
    try {//ww  w .  ja va2  s  . c  o m
        { // Save a SerialDemo object with a value of 5.
            FileOutputStream f = new FileOutputStream("/tmp/testing");
            ObjectOutputStream s = new ObjectOutputStream(f);
            SerialDemo d = new SerialDemo(5);

            s.writeObject(d);
            s.flush();
        }
        { // Now restore it and look at the value.
            FileInputStream f = new FileInputStream("/tmp/testing");
            ObjectInputStream s = new ObjectInputStream(f);
            SerialDemo d = (SerialDemo) s.readObject();

            System.out.println("SerialDemo.getVal() is: " + d.getVal());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:DemoPreparedStatementSetAsciiStream.java

public static void main(String[] args) {
    Connection conn = null;/*from   w ww. j av  a2s.c o  m*/
    PreparedStatement pstmt = null;
    String query = null;
    try {
        conn = getConnection();
        String fileName = "fileName.txt";
        File file = new File(fileName);
        int fileLength = (int) file.length();
        InputStream stream = (InputStream) new FileInputStream(file);

        query = "insert into  LONG_VARCHAR_TABLE(id, stream) values(?, ?)";
        pstmt = conn.prepareStatement(query);
        pstmt.setString(1, fileName);
        pstmt.setAsciiStream(2, stream, fileLength);

        int rowCount = pstmt.executeUpdate();
        System.out.println("rowCount=" + rowCount);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:GTKLookAndFeelDemo.java

public static void main(String[] args) {
    try {// ww w.  ja v a  2  s .  c  om
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    } catch (Exception e) {
        e.printStackTrace();
    }
    JLabel label = new JLabel("Label");
    JTextField field = new JTextField("www.java2s.com!");
    JList list = new JList(new String[] { "A", "B", "C" });
    JScrollPane listPane = new JScrollPane(list);
    listPane.setPreferredSize(new Dimension(250, 100));

    JScrollPane treePane = new JScrollPane(new JTree());
    treePane.setPreferredSize(new Dimension(250, 100));
    JButton button = new JButton("Click me");

    JPanel cp = new JPanel();
    cp.add(label);
    cp.add(field);
    cp.add(listPane);
    cp.add(treePane);
    cp.add(button);

    JFrame frame = new JFrame();
    frame.setTitle("Windows Look and Feel Demo");
    frame.setPreferredSize(new Dimension(280, 300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(cp);
    frame.pack();
    frame.setVisible(true);

}

From source file:com.domeastudio.util.JarClassLoader.java

public static void main(String[] args) {
    URL[] urls = new URL[] {};
    JarClassLoader jarClassLoader = new JarClassLoader(urls, Thread.currentThread().getContextClassLoader());
    try {/*from  w  w w .  j  av a2s. c om*/
        Geometry geometrySource = GeometryFormateHelper.getGeometry("POLYGON((1 1,3 4,6 7,10 45,1 1))");
        Geometry geometryTarget = GeometryFormateHelper.getGeometry("POINT(1 1)");
        //String path=jarClassLoader.getPath("lib/utility-1.0-SNAPSHOT.jar");
        jarClassLoader.addJar("utility-1.0-SNAPSHOT.jar");
        Class<?> clazz = jarClassLoader.loadClass("com.domeastudio.util.gis.SpatialOperationHelper");
        Class[] parameterTypes = new Class[] { Geometry.class, Geometry.class };
        Method method = clazz.getMethod("touches", parameterTypes);
        Boolean f = (Boolean) method.invoke(null, geometrySource, geometryTarget);
        System.out.println(f);
        jarClassLoader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // System.out.println("null:" + readWriteLicense.getLicenseName());
    // System.out.println("" + StringHelper.isEmptyAndBlank(""));
    //System.out.println("" + StringHelper.isEmptyAndBlank(" "));
}

From source file:egovframework.standalone.SampleMain.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "classpath:/egovframework/spring/context-*.xml" });

    EgovSampleService service = (EgovSampleService) context.getBean("sampleService");

    SampleDefaultVO searchVO = new SampleDefaultVO();

    try {/* w  ww.  ja  va2s. c  om*/
        List list = service.selectSampleList(searchVO);

        System.out.println("selectSampleList : " + list.size());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:TestGetXMLClient.java

public static void main(String args[]) {
    TestGetXMLClient client = new TestGetXMLClient();
    try {/*from   w  w  w  . j  a  v a 2  s  . c  o m*/
        client.testXML();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.devti.JavaXMPPBot.FakeDaemonContext.java

public static void main(String[] args) {
    JavaXMPPBot daemon = new JavaXMPPBot();
    try {/*from ww w .ja  v a 2s.c  o  m*/
        daemon.init(new FakeDaemonContext(args));
        daemon.start();
        while (Thread.activeCount() > 1) {
            Thread.sleep(1000);
        }
    } catch (Exception e) {
        e.printStackTrace();
        //System.err.println("Can't load a bot: " + e.getLocalizedMessage());
        System.exit(1);
    }
}

From source file:BigTableWithHeaderRowsPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    try {/*from   w  ww  . ja  v  a  2 s. c  om*/
        PdfWriter.getInstance(document, new FileOutputStream("BigTableWithHeaderRowsPDF.pdf"));

        document.open();
        int NumColumns = 12;

        PdfPTable datatable = new PdfPTable(NumColumns);
        int headerwidths[] = { 9, 4, 8, 10, 8, 11, 9, 7, 9, 10, 4, 10 }; // percentage
        datatable.setWidths(headerwidths);
        for (int i = 0; i < headerwidths.length; i++) {
            datatable.addCell("Header " + i);
        }
        datatable.setHeaderRows(1);

        datatable.getDefaultCell().setBorderWidth(1);
        for (int i = 1; i < 1000; i++) {
            if (i % 2 == 1) {
                datatable.getDefaultCell().setGrayFill(0.9f);
            }
            for (int x = 0; x < NumColumns; x++) {
                datatable.addCell("data");
            }
            if (i % 2 == 1) {
                datatable.getDefaultCell().setGrayFill(1);
            }
        }
        document.add(datatable);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}