List of usage examples for java.lang Class forName
@CallerSensitive public static Class<?> forName(String className) throws ClassNotFoundException
From source file:Spy.java
public static void main(String... args) throws Exception { Class<?> c = Class.forName("Spy"); Field[] flds = c.getDeclaredFields(); for (Field f : flds) { System.out.println(f.getDeclaringClass()); }// w ww . j a v a 2 s. c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { Class driverClass = Class.forName("org.hsqldb.jdbcDriver"); DriverManager.registerDriver((Driver) driverClass.newInstance()); // Print out all loaded JDBC drivers. java.util.Enumeration e = java.sql.DriverManager.getDrivers(); while (e.hasMoreElements()) { Object driverAsObject = e.nextElement(); System.out.println("JDBC Driver=" + driverAsObject); }/* w w w .j a v a 2 s .co m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root"); Statement st = con.createStatement(); st.executeUpdate("CREATE DATABASE myDB"); }
From source file:Main.java
public static void main(String... args) throws Exception { Class<?> c = Class.forName("java.lang.String"); Constructor[] allConstructors = c.getDeclaredConstructors(); for (Constructor ctor : allConstructors) { System.out.println(Modifier.toString(ctor.getModifiers())); }/*from w w w. j a v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root"); Statement st = con.createStatement(); st.executeUpdate("ALTER TABLE mytable DROP col"); System.out.println("Column is deleted successfully!"); }
From source file:MainClass.java
public static void main(String[] args) { try {/*from w w w . j av a 2 s. co m*/ String className = "org.gjt.mm.mysql.Driver"; Class driverObject = Class.forName(className); System.out.println("driverObject=" + driverObject); System.out.println("your installation of JDBC Driver OK."); } catch (Exception e) { System.out.println("Failed: JDBC Driver Error: " + e.getMessage()); } }
From source file:ConnectionExample.java
public static void main(String args[]) { try {/*from w w w . j a v a2 s. co m*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (Exception e) { System.out.println("JDBC-ODBC driver failed to load."); return; } try { Connection con = DriverManager.getConnection("jdbc:odbc:Inventory", "", ""); con.close(); } catch (Exception e) { System.out.println(e); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root"); Statement st = con.createStatement(); int n = st.executeUpdate("ALTER TABLE mytable DROP INDEX col"); System.out.println("Query OK, " + n + " rows affected."); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root"); Statement st = con.createStatement(); int n = st.executeUpdate("ALTER TABLE myTable CHANGE old_col new_col int"); System.out.println("Query OK, " + n + " rows affected"); }
From source file:Main.java
public static void main(String[] args) throws Exception { // returns the Class object for the class with the specified name Class cls = Class.forName("java.lang.ClassLoader"); // returns the name and package of the class System.out.println("Class found = " + cls.getName()); System.out.println("Package = " + cls.getPackage()); }