List of usage examples for java.lang Class forName
@CallerSensitive public static Class<?> forName(String className) throws ClassNotFoundException
From source file:UpdateableRs.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "yourName", "mypwd"); Statement stmt = conn.createStatement(); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery("SELECT ssn, name, salary FROM EMPLOYEES"); printRs(rs);//www. ja v a2 s.c o m rs.beforeFirst(); while (rs.next()) { double newSalary = rs.getDouble("salary") * 1.053; rs.updateDouble("salary", newSalary); rs.updateRow(); } printRs(rs); 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); String sql = "INSERT INTO my_table (col_string) VALUES(?)"; PreparedStatement pstmt = connection.prepareStatement(sql); // Insert 10 rows for (int i = 0; i < 10; i++) { // Set the value pstmt.setString(1, "row " + i); // Insert the row pstmt.executeUpdate();/*from w w w .j a va2 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(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); }
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.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); }
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(); // Column Name SQLServer Type Java Type String sql = "CREATE TABLE sqlserver_all_table(" + "col_boolean BIT, " // boolean + "col_byte TINYINT, " // byte + "col_short SMALLINT, " // short + "col_int INTEGER, " // int + "col_float REAL, " // float + "col_double DOUBLE PRECISION, " // double + "col_bigdecimal DECIMAL(13,0), " // BigDecimal; can also be NUMERIC(p,s) + "col_string VARCHAR(254), " // String + "col_date DATETIME, " // Date + "col_time DATETIME, " // Time + "col_timestamp TIMESTAMP, " // Timestamp + "col_characterstream TEXT, " // CharacterStream or AsciiStream (< 2 GBytes) + "col_binarystream IMAGE)"; // BinaryStream (< 2 GBytes) stmt.executeUpdate(sql);//from www . j a va2 s.c o m }
From source file:PrintResultSet.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc: Contacts"); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery("SELECT Name,Description,Qty,Cost FROM Stock"); ResultSetMetaData md = rs.getMetaData(); if (rs.getConcurrency() == ResultSet.CONCUR_UPDATABLE) System.out.println("UPDATABLE"); else//from w w w.j ava2 s. co m System.out.println("READ_ONLY"); int nColumns = md.getColumnCount(); for (int i = 1; i <= nColumns; i++) { System.out.print(md.getColumnLabel(i) + ((i == nColumns) ? "\n" : "\t")); } while (rs.next()) { rs.updateString("Street", "123 Main"); rs.updateRow(); for (int i = 1; i <= nColumns; i++) { System.out.print(rs.getString(i) + ((i == nColumns) ? "\n" : "\t")); } } }
From source file:Main.java
public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/booltest", "booltest", "booltest"); conn.prepareStatement("create table booltest (id bigint, truefalse varchar(10));").execute(); PreparedStatement stmt = conn.prepareStatement("insert into booltest (id, truefalse) values (?, ?);"); stmt.setLong(1, (long) 123); stmt.setBoolean(2, true);/*from w w w . j a va 2s. co m*/ stmt.execute(); stmt.setLong(1, (long) 456); stmt.setBoolean(2, false); stmt.execute(); ResultSet rs = conn.createStatement().executeQuery("select id, truefalse from booltest"); while (rs.next()) { System.out.println(rs.getLong(1) + " => " + rs.getBoolean(2)); } }
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.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); // Retrieve the current values of the row from the database resultSet.refreshRow();//from w ww. j a va 2 s . c o m }
From source file:TestThinApp.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:@dssw2k01:1521:orcl", "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();/* www. j a va 2 s. c o m*/ stmt.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); Statement stmt = connection.createStatement(); stmt.executeUpdate("DROP TABLE my_table"); }