Example usage for java.lang ClassNotFoundException printStackTrace

List of usage examples for java.lang ClassNotFoundException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Connection conn = null;/*from ww w.j a v  a 2 s .  c o m*/
    Statement stmt = null;
    try {
        conn = getConnection();
        stmt = conn.createStatement();
        stmt.executeUpdate(EMPLOYEE_TABLE);
        stmt.executeUpdate("insert into MyEmployees3(id, firstName) values(100, 'A')");
        stmt.executeUpdate("insert into MyEmployees3(id, firstName) values(200, 'B')");
        System.out.println("CreateEmployeeTableOracle: main(): table created.");
    } catch (ClassNotFoundException e) {
        System.out.println("error: failed to load Oracle driver.");
        e.printStackTrace();
    } catch (SQLException e) {
        System.out.println("error: failed to create a connection object.");
        e.printStackTrace();
    } catch (Exception e) {
        System.out.println("other error:");
        e.printStackTrace();
    } finally {
        try {
            stmt.close();
            conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:GenericReflectionTest.java

public static void main(String[] args) {
    // read class name from command line args or user input
    String name;/*w w w.j  a v a2  s  .c  om*/
    if (args.length > 0)
        name = args[0];
    else {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter class name (e.g. java.util.Collections): ");
        name = in.next();
    }

    try {
        // print generic info for class and public methods
        Class<?> cl = Class.forName(name);
        printClass(cl);
        for (Method m : cl.getDeclaredMethods())
            printMethod(m);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    Connection conn = null;//from www. j  a  v  a  2  s  .  c  o m
    Statement stmt = null;
    try {
        conn = getConnection();
        stmt = conn.createStatement();
        stmt.executeUpdate(EMPLOYEE_TABLE);
        stmt.executeUpdate("insert into MyEmployees3(id, firstName) values(100, 'A')");
        stmt.executeUpdate("insert into MyEmployees3(id, firstName) values(200, 'B')");
        System.out.println("CreateEmployeeTableMySQL: main(): table created.");
    } catch (ClassNotFoundException e) {
        System.out.println("error: failed to load MySQL driver.");
        e.printStackTrace();
    } catch (SQLException e) {
        System.out.println("error: failed to create a connection object.");
        e.printStackTrace();
    } catch (Exception e) {
        System.out.println("other error:");
        e.printStackTrace();
    } finally {
        try {
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void main(String... args) {
    try {/*from  ww  w  .  j  ava  2s  .  co  m*/
        Class<?> c = Class.forName(args[0]);
        out.format("Class:%n  %s%n%n", c.getCanonicalName());
        out.format("Modifiers:%n  %s%n%n", Modifier.toString(c.getModifiers()));

        out.format("Type Parameters:%n");
        TypeVariable[] tv = c.getTypeParameters();
        if (tv.length != 0) {
            out.format("  ");
            for (TypeVariable t : tv)
                out.format("%s ", t.getName());
            out.format("%n%n");
        } else {
            out.format("  -- No Type Parameters --%n%n");
        }

        out.format("Implemented Interfaces:%n");
        Type[] intfs = c.getGenericInterfaces();
        if (intfs.length != 0) {
            for (Type intf : intfs)
                out.format("  %s%n", intf.toString());
            out.format("%n");
        } else {
            out.format("  -- No Implemented Interfaces --%n%n");
        }

        out.format("Inheritance Path:%n");
        List<Class> l = new ArrayList<Class>();
        printAncestor(c, l);
        if (l.size() != 0) {
            for (Class<?> cl : l)
                out.format("  %s%n", cl.getCanonicalName());
            out.format("%n");
        } else {
            out.format("  -- No Super Classes --%n%n");
        }

        out.format("Annotations:%n");
        Annotation[] ann = c.getAnnotations();
        if (ann.length != 0) {
            for (Annotation a : ann)
                out.format("  %s%n", a.toString());
            out.format("%n");
        } else {
            out.format("  -- No Annotations --%n%n");
        }

        // production code should handle this exception more gracefully
    } catch (ClassNotFoundException x) {
        x.printStackTrace();
    }
}

From source file:ReflectionTest.java

public static void main(String[] args) {
    // read class name from command line args or user input
    String name;/*  w  w w. j a  va 2  s  .  c om*/
    if (args.length > 0)
        name = args[0];
    else {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter class name (e.g. java.util.Date): ");
        name = in.next();
    }

    try {
        // print class name and superclass name (if != Object)
        Class cl = Class.forName(name);
        Class supercl = cl.getSuperclass();
        String modifiers = Modifier.toString(cl.getModifiers());
        if (modifiers.length() > 0)
            System.out.print(modifiers + " ");
        System.out.print("class " + name);
        if (supercl != null && supercl != Object.class)
            System.out.print(" extends " + supercl.getName());

        System.out.print("\n{\n");
        printConstructors(cl);
        System.out.println();
        printMethods(cl);
        System.out.println();
        printFields(cl);
        System.out.println("}");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    System.exit(0);
}

From source file:de.alpharogroup.duplicate.files.desktoppane.MainApplication.java

/**
 * The main method.//  w  ww.jav  a2 s. c  o m
 *
 * @param args
 *            the arguments
 */
public static void main(final String[] args) {

    final ApplicationContext ctx = SpringApplicationContext.getInstance().getApplicationContext();
    final Resource resource = ctx.getResource("classpath:conf/log4j/log4jconfig.xml");

    try {
        DOMConfigurator.configure(resource.getURL());
    } catch (final FactoryConfigurationError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    final MainFrame mainFrame = MainFrame.getInstance();
    final DesktopMenu menu = DesktopMenu.getInstance();
    mainFrame.setJMenuBar(menu.getMenubar());

    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setSize(ScreenSizeExtensions.getScreenWidth(), ScreenSizeExtensions.getScreenHeight());
    mainFrame.setVisible(true);
    mainFrame.getDesktopPane().getDesktopManager().activateFrame(mainFrame.getInternalFrame());
    mainFrame.getDesktopPane().getDesktopManager().maximizeFrame(mainFrame.getInternalFrame());
    mainFrame.getInternalFrame().toFront();

    // Set default look and feel...
    try {
        UIManager.setLookAndFeel(LookAndFeels.SYSTEM.getLookAndFeelName());
        SwingUtilities.updateComponentTreeUI(mainFrame);
        mainFrame.setCurrentLookAndFeels(LookAndFeels.SYSTEM);
    } catch (final ClassNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (final InstantiationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (final IllegalAccessException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (final UnsupportedLookAndFeelException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}

From source file:Commons.dbcp.ManualPoolingDataSourceExample.java

public static void main(String[] args) {
    ////from  w w  w  . java 2s .  c o  m
    // First we load the underlying JDBC driver.
    // You need this if you don't use the jdbc.drivers
    // system property.
    //
    System.out.println("Loading underlying JDBC driver.");
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    System.out.println("Done.");

    //
    // Then, we set up the PoolingDataSource.
    // Normally this would be handled auto-magically by
    // an external configuration, but in this example we'll
    // do it manually.
    //
    System.out.println("Setting up data source.");
    ////ee  DataSource dataSource = setupDataSource(args[0]);
    DataSource dataSource = setupDataSource("jdbc:oracle:thin:@10.1.1.184:1521:UTF8");
    System.out.println("Done.");

    //
    // Now, we can use JDBC DataSource as we normally would.
    //
    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;

    try {
        System.out.println("Creating connection.");
        conn = dataSource.getConnection();
        System.out.println("Creating statement.");
        stmt = conn.createStatement();
        System.out.println("Executing statement.");
        rset = stmt.executeQuery(args[1]);
        System.out.println("Results:");
        int numcols = rset.getMetaData().getColumnCount();
        while (rset.next()) {
            for (int i = 1; i <= numcols; i++) {
                System.out.print("\t" + rset.getString(i));
            }
            System.out.println("");
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            rset.close();
        } catch (Exception e) {
        }
        try {
            stmt.close();
        } catch (Exception e) {
        }
        try {
            conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:PoolingDataSourceExample.java

public static void main(String[] args) {
    ///*from   w w  w  .jav  a 2  s  . co m*/
    // First we load the underlying JDBC driver.
    // You need this if you don't use the jdbc.drivers
    // system property.
    //
    System.out.println("Loading underlying JDBC driver.");
    try {
        Class.forName("org.h2.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    System.out.println("Done.");

    //
    // Then, we set up the PoolingDataSource.
    // Normally this would be handled auto-magically by
    // an external configuration, but in this example we'll
    // do it manually.
    //
    System.out.println("Setting up data source.");
    DataSource dataSource = setupDataSource(args[0]);
    System.out.println("Done.");

    //
    // Now, we can use JDBC DataSource as we normally would.
    //
    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;

    try {
        System.out.println("Creating connection.");
        conn = dataSource.getConnection();
        System.out.println("Creating statement.");
        stmt = conn.createStatement();
        System.out.println("Executing statement.");
        rset = stmt.executeQuery(args[1]);
        System.out.println("Results:");
        int numcols = rset.getMetaData().getColumnCount();
        while (rset.next()) {
            for (int i = 1; i <= numcols; i++) {
                System.out.print("\t" + rset.getString(i));
            }
            System.out.println("");
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (rset != null)
                rset.close();
        } catch (Exception e) {
        }
        try {
            if (stmt != null)
                stmt.close();
        } catch (Exception e) {
        }
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:ManualPoolingDataSourceExample.java

public static void main(String[] args) {
    ///*www  . j a v  a  2 s.  c o m*/
    // First we load the underlying JDBC driver.
    // You need this if you don't use the jdbc.drivers
    // system property.
    //
    System.out.println("Loading underlying JDBC driver.");
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    System.out.println("Done.");

    //
    // Then, we set up the PoolingDataSource.
    // Normally this would be handled auto-magically by
    // an external configuration, but in this example we'll
    // do it manually.
    //
    System.out.println("Setting up data source.");
    DataSource dataSource = setupDataSource(args[0]);
    System.out.println("Done.");

    //
    // Now, we can use JDBC DataSource as we normally would.
    //
    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;

    try {
        System.out.println("Creating connection.");
        conn = dataSource.getConnection();
        System.out.println("Creating statement.");
        stmt = conn.createStatement();
        System.out.println("Executing statement.");
        rset = stmt.executeQuery(args[1]);
        System.out.println("Results:");
        int numcols = rset.getMetaData().getColumnCount();
        while (rset.next()) {
            for (int i = 1; i <= numcols; i++) {
                System.out.print("\t" + rset.getString(i));
            }
            System.out.println("");
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (rset != null)
                rset.close();
        } catch (Exception e) {
        }
        try {
            if (stmt != null)
                stmt.close();
        } catch (Exception e) {
        }
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:javax.arang.DB.dbcp.ManualPoolingDataSourceExample.java

public static void main(String[] args) {
    ////from   www.  j ava 2 s  .c  o  m
    // First we load the underlying JDBC driver.
    // You need this if you don't use the jdbc.drivers
    // system property.
    //
    System.out.println("Loading underlying JDBC driver.");
    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    System.out.println("Done.");

    //
    // Then, we set up the PoolingDataSource.
    // Normally this would be handled auto-magically by
    // an external configuration, but in this example we'll
    // do it manually.
    //
    System.out.println("Setting up data source.");
    DataSource dataSource = setupDataSource("jdbc:mysql://root@localhost:3306:root:dkfkdsid");
    System.out.println("Done.");

    //
    // Now, we can use JDBC DataSource as we normally would.
    //
    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;

    try {
        System.out.println("Creating connection.");
        conn = dataSource.getConnection();
        System.out.println("Creating statement.");
        stmt = conn.createStatement();
        System.out.println("Executing statement.");
        rset = stmt.executeQuery(args[1]);
        System.out.println("Results:");
        int numcols = rset.getMetaData().getColumnCount();
        while (rset.next()) {
            for (int i = 1; i <= numcols; i++) {
                System.out.print("\t" + rset.getString(i));
            }
            System.out.println("");
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (rset != null)
                rset.close();
        } catch (Exception e) {
        }
        try {
            if (stmt != null)
                stmt.close();
        } catch (Exception e) {
        }
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
}