List of usage examples for java.lang Class forName
@CallerSensitive public static Class<?> forName(String className) throws ClassNotFoundException
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName); String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); DatabaseMetaData dbmd = connection.getMetaData(); // Get the list of system functions String[] systemFunctions = dbmd.getSystemFunctions().split(",\\s*"); Arrays.toString(systemFunctions); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName); String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); try {/*from w w w. ja v a 2 s . c om*/ connection.createStatement().execute("select wrong"); } catch (SQLException e) { while (e != null) { String message = e.getMessage(); String sqlState = e.getSQLState(); int errorCode = e.getErrorCode(); driverName = connection.getMetaData().getDriverName(); if (driverName.equals("Oracle JDBC Driver") && errorCode == 123) { } e = e.getNextException(); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName); String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); DatabaseMetaData dbmd = connection.getMetaData(); // Get the list of time and date functions String timedateFunctions[] = dbmd.getTimeDateFunctions().split(",\\s*"); Arrays.toString(timedateFunctions); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName); String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); Statement stmt = connection.createStatement(); String sql = "CREATE TABLE mysql_all_table(" + "col_boolean BOOL, " // boolean + "col_byte TINYINT, " // byte + "col_short SMALLINT, " // short + "col_int INTEGER, " // int + "col_long BIGINT, " // long + "col_float FLOAT, " // float + "col_double DOUBLE PRECISION, " // double + "col_bigdecimal DECIMAL(13,0), " // BigDecimal + "col_string VARCHAR(254), " // String + "col_date DATE, " // Date + "col_time TIME, " // Time + "col_timestamp TIMESTAMP, " // Timestamp + "col_asciistream TEXT, " // AsciiStream (< 2^16 bytes) + "col_binarystream LONGBLOB, " // BinaryStream (< 2^32 bytes) + "col_blob BLOB)"; // Blob (< 2^16 bytes) stmt.executeUpdate(sql);//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 { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName); String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); Statement stmt = connection.createStatement(); // Create table called my_table String sql = "CREATE TABLE my_table(col_string VARCHAR(254))"; stmt.executeUpdate(sql);// www. ja v a2 s. c om }
From source file:TestThinNet8App.java
public static void main(String args[]) throws ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver"); // DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@(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 Thin driver tester '||USER||'!' result from dual"); while (rset.next()) System.out.println(rset.getString(1)); rset.close();/*w w w . j a v a 2 s . c o m*/ stmt.close(); conn.close(); }
From source file:JdbcDemo.java
public static void main(String args[]) throws Exception { String query = "SELECT Name,Description,Qty,Cost FROM Stock"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Inventory"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String name = rs.getString("Name"); String desc = rs.getString("Description"); int qty = rs.getInt("Qty"); float cost = rs.getFloat("Cost"); System.out.println(name + ", " + desc + "\t: " + qty + "\t@ $" + cost); }//from www . j av a 2 s.co m con.close(); }
From source file:Main.java
public static void main(String... args) { try {/*from ww w . ja v a2 s.com*/ Class<?> c = Class.forName("Main"); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { Annotation[][] types = m.getParameterAnnotations(); } } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName); String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); DatabaseMetaData dmd = connection.getMetaData(); if (dmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { System.out.println("Updatable result sets are supported"); } else {/*from ww w. jav a 2 s . co m*/ System.out.println("Updatable result sets are not supported"); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "oracle.jdbc.driver.OracleDriver"; Class.forName(driverName); String serverName = "127.0.0.1"; String portNumber = "1521"; String sid = "mydatabase"; String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); Statement stmt = connection.createStatement(); // IN is the default mode for parameter, so both 'x VARCHAR' and 'x IN VARCHAR' are valid String procedure = "CREATE OR REPLACE PROCEDURE myprocin(x VARCHAR) IS " + "BEGIN " + "INSERT INTO oracle_table VALUES(x); " + "END;"; stmt.executeUpdate(procedure);// w w w . ja va2 s . co m }