List of usage examples for java.lang Exception printStackTrace
public void printStackTrace()
From source file:VerticalTextPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4, 50, 50, 50, 50); try {/*from www. ja va2s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("VerticalTextPDF.pdf")); document.open(); PdfTemplate template = writer.getDirectContent().createTemplate(20, 20); BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false); String text = "Vertical"; float size = 16; float width = bf.getWidthPoint(text, size); template.beginText(); template.setFontAndSize(bf, size); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); Image img = Image.getInstance(template); img.setRotationDegrees(90); PdfPTable table = new PdfPTable(1); table.addCell(new PdfPCell(img)); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:CellBorderColorsPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4); try {/*from w w w . ja v a 2 s .c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("CellBorderColorsPDF.pdf")); document.open(); PdfPTable table = new PdfPTable(1); PdfPCell cell = new PdfPCell(new Paragraph("test colors:")); table.addCell(cell); cell = new PdfPCell(new Paragraph("red")); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(Color.red); table.addCell(cell); cell = new PdfPCell(new Paragraph("green")); cell.setBorder(Rectangle.BOTTOM); cell.setBorderColorBottom(Color.magenta); cell.setBorderWidthBottom(10f); cell.setBackgroundColor(Color.green); table.addCell(cell); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:SplitRowsPDF.java
public static void main(String[] args) { Document document1 = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {/*from w w w . j a va2s. c o m*/ PdfWriter.getInstance(document1, new FileOutputStream("SplitRowsPDF.pdf")); document1.open(); String text = "Text Text Text Text Text Text Text Text Text"; PdfPTable table = new PdfPTable(2); PdfPCell largeCell; Phrase phrase; for (int i = 0; i < 10; i++) { phrase = new Phrase(text); for (int j = 0; j < i; j++) { phrase.add(new Phrase(text)); } if (i == 7) phrase = new Phrase(text); table.addCell(String.valueOf(i)); largeCell = new PdfPCell(phrase); table.addCell(largeCell); } document1.add(table); table.setSplitLate(true); } catch (Exception de) { de.printStackTrace(); } document1.close(); }
From source file:TextPatternShapePDF.java
public static void main(String[] args) { Document document = new Document(); try {//from ww w . j a v a2 s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TextPatternShapePDF.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont("Times-Roman", "winansi", false); PdfPatternPainter p = cb.createPattern(30f, 30f, 30f, 30f); p.setGrayFill(0.3f); p.setFontAndSize(bf, 12); p.beginText(); p.setTextMatrix(1f, 0f, 0f, 1f, 0f, 0f); p.showText("A B C D"); p.endText(); p.moveTo(0f, 0f); p.lineTo(30f, 30f); p.stroke(); cb.setPatternFill(p); cb.circle(150f, 400f, 150f); cb.fillStroke(); } catch (Exception e) { e.printStackTrace(); } document.close(); }
From source file:DocumentPageEventPDF.java
public static void main(String args[]) { try {// w ww . ja v a 2 s . c om Document doc = new Document(PageSize.A4, 50, 50, 100, 72); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("DocumentPageEventPDF.pdf")); writer.setPageEvent(new DocumentPageEventPDF()); doc.open(); Paragraph p = new Paragraph("text"); doc.add(p); doc.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:test.jackson.TestJacksonPoly.java
public static void main(String[] args) { ObjectMapper objectMapper = new ObjectMapper(); Animal myDog = new Dog("ruffus", "english shepherd"); Animal myCat = new Cat("goya", "mice"); try {/*from ww w.ja v a 2 s .c o m*/ String dogJson = objectMapper.writeValueAsString(myDog); System.out.println(dogJson); Animal deserializedDog = objectMapper.readValue(dogJson, Animal.class); System.out.println("Deserialized dogJson Class: " + deserializedDog.getClass().getSimpleName()); String catJson = objectMapper.writeValueAsString(myCat); Animal deseriliazedCat = objectMapper.readValue(catJson, Animal.class); System.out.println("Deserialized catJson Class: " + deseriliazedCat.getClass().getSimpleName()); } catch (Exception e) { e.printStackTrace(); } }
From source file:CountRecordsUsingPreparedStatement.java
public static void main(String[] args) { ResultSet rs = null;//from w w w .ja va 2s . c om Connection conn = null; PreparedStatement pstmt = null; try { conn = getConnection(); String query = "select count(*) from tableName"; pstmt = conn.prepareStatement(query); rs = pstmt.executeQuery(); if (rs.next()) { int numberOfRows = rs.getInt(1); System.out.println("numberOfRows= " + numberOfRows); } else { System.out.println("error: could not get the record counts"); } } catch (Exception e) { e.printStackTrace(); } finally { try { rs.close(); pstmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:nl.mindef.c2sc.nbs.olsr.pud.uplink.server.Main.java
public static void main(String[] args) { logger.info("RelayServer starting"); try {/*from ww w . j a v a2 s . c o m*/ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/application-context.xml"); logger.info("RelayServer started"); context.start(); UplinkReceiver uplinkReceiver = (UplinkReceiver) context.getBean("UplinkReceiver"); uplinkReceiver.join(); logger.info("RelayServer stopped"); context.stop(); context.close(); context.destroy(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.everm.httpclient.HttpClientTest.java
/** * @param args/* w w w. j a v a 2 s . c om*/ */ public static void main(String[] args) { String uri = "http://samsung-cps-000.s3.amazonaws.com/PDF/-137219737027956571"; HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(uri); HttpResponse response = null; long startTime = System.currentTimeMillis(); try { httpGet.addHeader("Date", "Mon, 18 Feb 2013 08:14:01 GMT"); httpGet.addHeader("Authorization", "AWS AKIAIULRL33KVNJCCNAQ:ac4P+U1n+ib/PkOCqyuH4lt9hK8="); // for (int i = 0; i < 100; i++) { response = client.execute(httpGet); // System.out.println(i + "___" + response.getStatusLine()); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); // } } catch (Exception e) { e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("elapsed time :" + (endTime - startTime)); }
From source file:InsertDateToOracle.java
public static void main(String args[]) throws Exception { String INSERT_RECORD = "insert into TestDates(id, date_column, " + "time_column, timestamp_column) values(?, ?, ?, ?)"; Connection conn = null;//from ww w . j a v a2 s . c om PreparedStatement pstmt = null; try { conn = getConnection(); pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "001"); java.util.Date date = new java.util.Date(); long t = date.getTime(); java.sql.Date sqlDate = new java.sql.Date(t); java.sql.Time sqlTime = new java.sql.Time(t); java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(t); System.out.println("sqlDate=" + sqlDate); System.out.println("sqlTime=" + sqlTime); System.out.println("sqlTimestamp=" + sqlTimestamp); pstmt.setDate(2, sqlDate); pstmt.setTime(3, sqlTime); pstmt.setTimestamp(4, sqlTimestamp); pstmt.executeUpdate(); } catch (Exception e) { e.printStackTrace(); System.out.println("Failed to insert the record."); } finally { pstmt.close(); conn.close(); } }