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:Main.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            try {
                frame.add(new MyPanel());
            } catch (Exception e) {
                e.printStackTrace();
            }// www . ja v  a 2 s .c om
            frame.setSize(250, 250);
            frame.setVisible(true);
        }
    });
}

From source file:ExecuteMethod.java

public static void main(String[] args) {
    Connection conn = null;//from   w w w. j a v  a 2  s .  c  om
    Statement stmt = null;
    ResultSet rs = null;
    boolean executeResult;
    try {
        String driver = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driver).newInstance();
        System.out.println("Connecting to database...");
        String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL";
        conn = DriverManager.getConnection(jdbcUrl, "test", "mypwd");
        stmt = conn.createStatement();

        String sql = "INSERT INTO Employees VALUES" + "(1,'G','4351',{d '1996-12-31'},500)";
        executeResult = stmt.execute(sql);
        processExecute(stmt, executeResult);

        sql = "SELECT * FROM Employees ORDER BY hiredate";
        executeResult = stmt.execute(sql);
        processExecute(stmt, executeResult);
    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (SQLException se) {
            se.printStackTrace();
        }
    }
}

From source file:com.kookoo.outbound.OutboundTest.java

public static void main(String a[]) {
    try {/*w w  w.j  a  v  a  2 s.  c o  m*/
        String server_ip = "http://XXXX:8080"; /*change to your web server*/
        String phone_no1 = "09985XXXXX";/*change number to your numbers*/
        String phone_no2 = "09985XXXXX";/*change number to your numbers*/
        String api_key = "KKXXXXX";/*kookoo api key*/
        String kookoo_number = "91xxxxx";/*kookoo assigned number*/

        Date d = new Date();
        String trackId = "" + d.getTime();
        String url = "http://kookoo.in/outbound/outbound.php";
        URIBuilder uribuilder = new URIBuilder(url);
        uribuilder.addParameter("api_key", api_key);
        uribuilder.addParameter("phone_no", phone_no1);
        uribuilder.addParameter("caller_id", kookoo_number);
        /*assigned kookoo number*/
        uribuilder.addParameter("url",
                server_ip + "/kookoocall/outboundcall?number2=" + phone_no2 + "&trackId=" + trackId);
        uribuilder.addParameter("callback_url",
                server_ip + "/kookoocall/outbound_callstatus?number2=" + phone_no2 + "&trackId=" + trackId);

        URI uri = uribuilder.build();
        System.out.println("Final Outboud API url " + uri);
        HttpGet request = new HttpGet(uri);
        HttpClient client = HttpClientBuilder.create().build();
        HttpResponse response = client.execute(request);

        String responseString = new BasicResponseHandler().handleResponse(response);
        System.out.println(responseString);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:StartExamples.java

/**
 * Main function, starts the jetty server.
 * /*from   w  w w .ja  v a2  s  . co m*/
 * @param args
 * @throws Exception 
 */

public static void main(String[] args) throws Exception {
    System.setProperty("org.mortbay.jetty.Request.maxFormContentSize", "20000000");
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.setConnectors(new Connector[] { connector });
    WebAppContext web = new WebAppContext("webroot", "/");
    server.addHandler(web);
    try {
        server.start();
        server.join();
        // server.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(100);
    }
}

From source file:StreamTaggerDemo.java

public static void main(String args[]) {
    try {//from  w  ww . j  a  v  a  2 s  . co  m
        System.setProperty("sen.home", "../Sen1221/senhome-ipadic");
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
        System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "FATAL");

        if (args.length != 2) {
            System.err.println("usage: java StreamTaggerDemo <filename> <encoding>");
            System.exit(1);
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]), args[1]));
        // String confPath = System.getProperty("sen.home")
        // + System.getProperty("file.separator") + "conf/sen.xml";
        // StreamTagger tagger = new StreamTagger((Reader) br, confPath);
        StreamTagger tagger = new StreamTagger((Reader) br);

        // BufferedReader is = new BufferedReader(System.in);

        while (tagger.hasNext()) {
            Token token = tagger.next();
            System.out.println(token.toString() + "\t(" + token.getBasicString() + ")" + "\t" + token.getPos()
                    + "(" + token.start() + "," + token.end() + "," + token.length() + ")\t"
                    + token.getReading() + "\t" + token.getPronunciation());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:basic.BasicExample.java

/**
 * @param args/*from  w w w  .jav a  2s .  c o  m*/
 */
public static void main(String[] args) {
    try {
        new BasicExample();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    Connection connection = null;
    PreparedStatement statement = null;
    try {//from   ww  w  .ja v a 2  s. c  om
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        String url = "jdbc:mysql://localhost/database";
        connection = DriverManager.getConnection(url, "username", "password");

        String sql = "UPDATE employees SET email = ? WHERE employee_id = ?";
        statement = connection.prepareStatement(sql);

        statement.setString(1, "a@a.com");
        statement.setLong(2, 1);
        statement.addBatch();

        statement.setString(1, "b@b.com");
        statement.setLong(2, 2);
        statement.addBatch();

        statement.setString(1, "c@c.com");
        statement.setLong(2, 3);
        statement.addBatch();

        statement.executeBatch();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
            } // nothing we can do
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
            } // nothing we can do
        }
    }
}

From source file:Buffers.java

public static void main(String[] args) {
    try {//w ww . ja  v  a  2s .c  o m
        float[] floats = { 6.61E-39F, 9.918385E-39F };

        ByteBuffer bb = ByteBuffer.allocate(floats.length * 4);

        FloatBuffer fb = bb.asFloatBuffer();
        fb.put(floats);

        CharBuffer cb = bb.asCharBuffer();
        System.out.println(cb.toString());

    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    Connection conn = null;/*from  w w w  . j  av a2  s.  c  om*/
    Statement stmt = null;
    try {
        Class.forName(JDBC_DRIVER);
        conn = DriverManager.getConnection(DB_URL, USER, PASS);
        stmt = conn.createStatement();
        String sql = "SELECT id, first, last, age FROM Employees";
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            int id = rs.getInt("id");
            int age = rs.getInt("age");
            String first = rs.getString("first");
            String last = rs.getString("last");

            System.out.print("ID: " + id);
            System.out.print(", Age: " + age);
            System.out.print(", First: " + first);
            System.out.println(", Last: " + last);
        }
        rs.close();
        stmt.close();
        conn.close();
    } catch (SQLException se) {
        se.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (stmt != null)
                stmt.close();
            if (conn != null)
                conn.close();
        } catch (SQLException se) {
            se.printStackTrace();
        }
    }
}

From source file:NestedTableCellPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {// www  .j ava 2 s .co m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("NestedTableCellPDF.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfPTable pageTot = new PdfPTable(1);
        pageTot.getDefaultCell().setPadding(0f);
        pageTot.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        pageTot.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        pageTot.setWidthPercentage(100f);

        PdfPTable cell = new PdfPTable(1);
        cell.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        cell.getDefaultCell().setPadding(0f);

        PdfPCell info = new PdfPCell(new Phrase("Outside"));
        info.setBorder(Rectangle.NO_BORDER);
        pageTot.addCell(info);

        PdfPCell shipment = new PdfPCell(new Phrase(new Chunk("Cell")));
        shipment.setFixedHeight(100);
        shipment.setPaddingTop(5f);
        shipment.setPaddingBottom(10f);
        shipment.setBorder(Rectangle.BOX);
        shipment.setVerticalAlignment(Element.ALIGN_TOP);
        shipment.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addCell(shipment);

        pageTot.addCell(cell);

        document.add(pageTot);
    } catch (Exception e) {
        e.printStackTrace();
    }
    document.close();
}