List of usage examples for java.lang Exception printStackTrace
public void printStackTrace()
From source file:NameLister.java
public static void main(String args[]) { if (args.length != 1) { System.err.println("Usage: java NameLister xmlfile.xml"); System.exit(-1);/* w ww . j a va2s . co m*/ } try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new DefaultHandler() { boolean name = false; public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equalsIgnoreCase("NAME")) { name = true; } } public void characters(char ch[], int start, int length) throws SAXException { if (name) { System.out.println("Name: " + new String(ch, start, length)); name = false; } } }; saxParser.parse(args[0], handler); } catch (Exception e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String args[]) { Connection conn = null;//from w w w.j ava 2 s .com Statement stmt = null; ResultSet rs = null; try { conn = getConnection(); stmt = conn.createStatement(); String query = "select EmployeeID, LastName, FirstName from Employees"; rs = stmt.executeQuery(query); while (rs.next()) { System.out.println(rs.getString("EmployeeID") + " " + rs.getString("LastName") + " " + rs.getString("FirstName")); } } catch (Exception e) { // handle the exception e.printStackTrace(); System.err.println(e.getMessage()); } finally { try { rs.close(); stmt.close(); conn.close(); } catch (Exception ee) { ee.printStackTrace(); } } }
From source file:geniuswebsocket.EchoGottox.java
/** * @param args/*from w ww . j a va 2 s .c om*/ */ public static void main(String[] args) { try { new EchoGottox(); } catch (Exception e) { e.printStackTrace(); } }
From source file:TableHeaderPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50); try {/*from w w w . j a v a 2s .co m*/ PdfWriter.getInstance(document, new FileOutputStream("TableHeaderPDF.pdf")); document.open(); Table datatable = new Table(3); int headerwidths[] = { 10, 24, 12 }; datatable.setWidths(headerwidths); datatable.setWidth(46); datatable.setPadding(3); Cell cell = new Cell(new Phrase("title", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setLeading(30); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); datatable.addCell(cell); datatable.setDefaultCellBorderWidth(2); datatable.setDefaultHorizontalAlignment(1); datatable.addCell("Header 1"); datatable.addCell("Header \n 2"); datatable.addCell("Header 3"); datatable.endHeaders(); datatable.setDefaultCellBorderWidth(1); datatable.setDefaultHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell("1"); datatable.addCell("2"); datatable.addCell("3"); datatable.setDefaultHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("4"); datatable.addCell("5"); datatable.addCell("6"); document.add(datatable); } catch (Exception e) { e.printStackTrace(); } document.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { new Thread(() -> { int submitCount = 0; while (submitCount < 10) { if (!updating) { futureList.add(pool.submit(callable)); submitCount++;//from w ww . ja v a 2 s. c o m } try { Thread.sleep(1000); // arbitrary } catch (Exception e) { e.printStackTrace(); } } }).start(); // update thread new Thread(() -> { int updateCount = 0; while (updateCount < 5) { doUpdate(); updateCount++; try { Thread.sleep(2000); } catch (Exception e) { e.printStackTrace(); } } }).start(); }
From source file:MainClass.java
public static void main(String[] args) { Connection connection = null; Statement statement = null;/* w w w. ja v a2s . c o m*/ try { Class.forName("org.hsqldb.jdbcDriver").newInstance(); String url = "jdbc:hsqldb:hsqldb\\demoDatabase"; connection = DriverManager.getConnection(url, "username", "password"); connection.setAutoCommit(false); statement = connection.createStatement(); String update1 = "UPDATE employees SET email = 'a@b.com' WHERE email = 'a@a.com'"; statement.executeUpdate(update1); Savepoint savepoint1 = connection.setSavepoint("savepoint1"); String update2 = "UPDATE employees SET email = 'b@b.com' WHERE email = 'b@c.com'"; statement.executeUpdate(update2); Savepoint savepoint2 = connection.setSavepoint("savepoint2"); String update3 = "UPDATE employees SET email = 'c@c.com' WHERE email = 'c@d.com'"; statement.executeUpdate(update3); Savepoint savepoint3 = connection.setSavepoint("savepoint3"); String update4 = "UPDATE employees SET email = 'd@d.com' WHERE email = 'd@e.com'"; statement.executeUpdate(update4); Savepoint savepoint4 = connection.setSavepoint("savepoint4"); String update5 = "UPDATE employees SET email = 'e@e.com' WHERE email = 'e@f.com'"; statement.executeUpdate(update5); Savepoint savepoint5 = connection.setSavepoint("savepoint5"); connection.rollback(savepoint3); connection.commit(); } 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:TestCreateConnectionWithProperties_MySQL.java
public static void main(String[] args) { Connection conn = null;//from www.j a va 2 s .co m try { // get connection to an Oracle database conn = getConnection(); System.out.println("conn=" + conn); } catch (Exception e) { // handle the exception e.printStackTrace(); System.exit(1); } finally { // release database resources try { conn.close(); } catch (Exception ignore) { } } }
From source file:ListMObjects.java
public static void main(String[] args) { System.out.println("Executing List MObjects"); try {/* w w w .j a va 2 s . co m*/ URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsListMObjects request = new ParamsListMObjects(); SuccessListMObjects result = port.listMObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessListMObjects.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.googlecode.erca.framework.io.in.CtxContextParser.java
public static void main(String[] args) { try {/*from w w w . jav a2s . c o m*/ CtxContextParser parser = new CtxContextParser("doc/samples/ctx/simpletest.ctx"); parser.parse(); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.toronto.cs.cidb.obo2solr.Main.java
public static void main(String args[]) { Options options = generateOptions(); try {/*ww w. ja v a2s .com*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (!cmd.hasOption(OBO_DB_LOCATION_OPTION) || cmd.hasOption(HELP_OPTION)) { showUsage(options); System.exit(cmd.hasOption(HELP_OPTION) ? 0 : 1); } ParameterPreparer paramPrep = new ParameterPreparer(); SolrUpdateGenerator generator = new SolrUpdateGenerator(); File input = paramPrep.getInputFileHandler(cmd.getOptionValue(OBO_DB_LOCATION_OPTION)); File output = paramPrep.getOutputFileHandler( cmd.getOptionValue(OUTPUT_XML_LOCATION_OPTION, DEFAULT_OUTPUT_XML_LOCATION)); Map<String, Double> fieldSelection = paramPrep .getFieldSelection(cmd.getOptionValue(INDEX_FILEDS_OPTION, "")); generator.transform(input, output, fieldSelection); } catch (Exception ex) { ex.printStackTrace(); } }