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... args) { try {/*from w w w .ja va2 s. com*/ Class<?> c = Class.forName("Main"); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { TypeVariable[] types = m.getTypeParameters(); for (TypeVariable t : types) { System.out.println(t); } } } 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); // Create a statement that will return updatable result sets Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Primary key must be specified so that the result set is updatable ResultSet resultSet = stmt.executeQuery("SELECT col_string FROM my_table"); }
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(); ResultSet resultSet = stmt.executeQuery("SELECT COUNT(*) FROM my_table"); // Get the number of rows from the result set resultSet.next();//from ww w . ja v a 2 s.c om int rowcount = resultSet.getInt(1); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db"); Statement stat = conn.createStatement(); stat.executeUpdate("drop table if exists people;"); stat.executeUpdate("create table people (name, occupation);"); PreparedStatement prep = conn.prepareStatement("insert into people values (?, ?);"); prep.setString(1, "G"); prep.setString(2, "politics"); prep.addBatch();/*from www.j a va 2 s .c om*/ prep.setString(1, "Turing"); prep.setString(2, "computers"); prep.addBatch(); prep.setString(1, "W"); prep.setString(2, "Tester"); prep.addBatch(); conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(true); ResultSet rs = stat.executeQuery("select * from people;"); while (rs.next()) { System.out.println("name = " + rs.getString("name")); System.out.println("job = " + rs.getString("occupation")); } rs.close(); conn.close(); }
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(); String[] keywords = dbmd.getSQLKeywords().split(",\\s*"); Arrays.toString(keywords);/* ww w . j a va 2 s. co 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); // Create an updatable result set Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); // Delete the first row resultSet.first();// w w w. j ava2 s .c o m resultSet.deleteRow(); }
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 string functions String[] stringFunctions = dbmd.getStringFunctions().split(",\\s*"); Arrays.toString(stringFunctions); }
From source file:MethodInspector.java
public static void main(String[] arguments) { Class inspect;/*w w w. j a va 2 s .c om*/ try { if (arguments.length > 0) inspect = Class.forName(arguments[0]); else inspect = Class.forName("MethodInspector"); Method[] methods = inspect.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method methVal = methods[i]; Class returnVal = methVal.getReturnType(); int mods = methVal.getModifiers(); String modVal = Modifier.toString(mods); Class[] paramVal = methVal.getParameterTypes(); StringBuffer params = new StringBuffer(); for (int j = 0; j < paramVal.length; j++) { if (j > 0) params.append(", "); params.append(paramVal[j].getName()); } System.out.println("Method: " + methVal.getName() + "()"); System.out.println("Modifiers: " + modVal); System.out.println("Return Type: " + returnVal.getName()); System.out.println("Parameters: " + params + "\n"); } } catch (ClassNotFoundException c) { System.out.println(c.toString()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection connection = null; try {/*from w ww .j a v a 2s . c o m*/ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); connection = DriverManager.getConnection("jdbc:sqlserver://MYSERVER;databaseName=MYDATABASE", "USERID", "PASSWORD"); connection.setAutoCommit(false); Statement statement = connection.createStatement(); statement.executeUpdate("UPDATE Table1 SET Value = 1 WHERE Name = 'foo'"); statement.executeUpdate("UPDATE Table2 SET Value = 2 WHERE Name = 'bar'"); connection.commit(); } catch (SQLException ex) { connection.rollback(); } }
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 numeric functions String[] numericFunctions = dbmd.getNumericFunctions().split(",\\s*"); Arrays.toString(numericFunctions); }