List of usage examples for java.lang Class forName
@CallerSensitive public static Class<?> forName(String className) throws ClassNotFoundException
From source file:X.java
public static void main(String[] args) { try {/*w w w.j a v a 2 s. co m*/ Class<?> clazz = Class.forName("X"); X x = (X) clazz.newInstance(); Class[] argTypes = { String.class }; Method method = clazz.getMethod("objectMethod", argTypes); Annotation[] annos = method.getAnnotations(); for (Annotation anno : annos) { System.out.println(anno); } System.out.println(); } catch (Exception e) { System.err.println(e); } }
From source file:TestOCINet8App.java
public static void main(String args[]) throws ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver"); // or you can use: // DriverManager.registerDriver( // new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@(DESCRIPTION = " + "(ADDRESS_LIST = (ADDRESS = " + "(PROTOCOL = TCP)(HOST = dssw2k01)(PORT = 1521)))" + "(CONNECT_DATA = (SERVICE_NAME = dssw2k01)))", "scott", "tiger"); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery("select 'Hello OCI driver tester '||USER||'!' result from dual"); while (rset.next()) System.out.println(rset.getString(1)); rset.close();/*from w ww.j a v a 2 s.c o m*/ stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER); Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); boolean isBatchingSupported = metadata.supportsBatchUpdates(); System.out.println("Batching Supported = " + isBatchingSupported); connection.close();/*from w w w . j a va2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER); Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); boolean isSupportTransaction = metadata.supportsTransactions(); System.out.println("Support Transaction = " + isSupportTransaction); connection.close();// w w w . j ava 2s .c om }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER); Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); int maxLength = metadata.getMaxTableNameLength(); System.out.println("Max Table Name Length = " + maxLength); connection.close();/*from ww w.j ava 2 s . co m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER); Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); int maxConnection = metadata.getMaxConnections(); System.out.println("Maximum Connection = " + maxConnection); connection.close();/*from w w w .j av a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection(url, username, password); conn.setAutoCommit(false);/*from w ww .ja v a2 s . c o m*/ String sql = "INSERT INTO documents (name, description, data) VALUES (?, ?, ?)"; PreparedStatement stmt = conn.prepareStatement(sql); stmt.setString(1, "a.txt"); stmt.setString(2, "b"); File data = new File("C:\\a.txt"); FileReader reader = new FileReader(data); stmt.setCharacterStream(3, reader, (int) data.length()); stmt.execute(); conn.commit(); reader.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) { Connection conn = null;/* w ww . j a va2 s . c o m*/ Statement stmt = null; ResultSet rs = null; 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, "yourName", "mypwd"); stmt = conn.createStatement(); try { rs = stmt.executeQuery("Select * from no_table_exisits"); } catch (SQLException seRs) { String exMsg = "Message from MySQL Database"; String exSqlState = "Exception"; SQLException mySqlEx = new SQLException(exMsg, exSqlState); seRs.setNextException(mySqlEx); throw seRs; } } catch (SQLException se) { int count = 1; while (se != null) { System.out.println("SQLException " + count); System.out.println("Code: " + se.getErrorCode()); System.out.println("SqlState: " + se.getSQLState()); System.out.println("Error Message: " + se.getMessage()); se = se.getNextException(); count++; } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER); Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); String[] functions = metadata.getTimeDateFunctions().split(",\\s*"); for (int i = 0; i < functions.length; i++) { String function = functions[i]; System.out.println("Function = " + function); }//from w w w .j a va 2 s. co m connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER); Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); String[] functions = metadata.getSystemFunctions().split(",\\s*"); for (int i = 0; i < functions.length; i++) { String function = functions[i]; System.out.println("Function = " + function); }/*from ww w .j a va2 s . c o m*/ }