Example usage for java.lang Class forName

List of usage examples for java.lang Class forName

Introduction

In this page you can find the example usage for java.lang Class forName.

Prototype

@CallerSensitive
public static Class<?> forName(String className) throws ClassNotFoundException 

Source Link

Document

Returns the Class object associated with the class or interface with the given string name.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    Connection con = null;//  ww w. ja v a  2s .c om
    Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
    con = DriverManager.getConnection("jdbc:cassandra://localhost:9160/Keyspace");

    String query = "SELECT * FROM column_family where gender=f ";

    Statement stmt = con.createStatement();
    ResultSet result = stmt.executeQuery(query);

    while (result.next()) {
        System.out.println(result.getString("user_name"));
        System.out.println(result.getString("gender"));
        System.out.println(result.getString("password"));
    }
    con.close();
}

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();
    String function = "CREATE OR REPLACE FUNCTION myfuncinout(x IN OUT VARCHAR) RETURN VARCHAR IS "
            + "BEGIN x:= x||'outvalue'; RETURN 'a returned string'; END;";
    stmt.executeUpdate(function);/*  w w w. jav a2s  .co m*/

}

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();
    String function = "CREATE OR REPLACE FUNCTION myfuncin(x VARCHAR) RETURN VARCHAR IS "
            + "BEGIN RETURN 'a return string'||x; END;";
    stmt.executeUpdate(function);/* w  w  w. ja  v a2  s .  c o m*/

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int count = 0;
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    String sql = "SELECT title,year_made FROM product WHERE year_made >= ? AND year_made <= ?";
    PreparedStatement prest = con.prepareStatement(sql);
    prest.setInt(1, 2000);//from w ww  .  j a v a  2s  .c om
    prest.setInt(2, 2009);
    ResultSet rs = prest.executeQuery();
    while (rs.next()) {
        String mov_name = rs.getString(1);
        int mov_year = rs.getInt(2);
        count++;
        System.out.println(mov_name + "\t" + "- " + mov_year);
    }
    System.out.println("Number of records: " + count);
    prest.close();
    con.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    Class.forName(driver).newInstance();
    System.out.println("Connecting to database...");
    String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL";
    Connection conn = DriverManager.getConnection(jdbcUrl, "yourName", "mypwd");
    CallableStatement cstmt = conn.prepareCall("{call getEmpName (?,?)}");
    cstmt.setInt(1, 111111111);//from ww w.j  av  a2 s  .co  m
    cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);
    cstmt.execute();
    String empName = cstmt.getString(2);
    System.out.println(empName);
    conn.close();

}

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();
    stmt.execute("CREATE TYPE object2 AS OBJECT(col_string2 VARCHAR(30), col_integer2 NUMBER)");
    stmt.execute("CREATE TYPE object1 AS OBJECT(col_string1 VARCHAR(30), col_integer2 object2)");
    stmt.execute("CREATE TABLE object1_table(col_integer NUMBER, col_object1 object1)");
    stmt.execute("INSERT INTO object1_table VALUES(1, object1('str1', object2('obj2str1', 123)))");
}

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);
    String procedure = "CREATE OR REPLACE PROCEDURE myprocinout(x IN OUT VARCHAR) IS BEGIN "
            + "INSERT INTO oracle_table VALUES(x); " // Use x as IN parameter
            + "x := 'outvalue'; " // Use x as OUT parameter
            + "END;";
    Statement stmt = connection.createStatement();
    stmt.executeUpdate(procedure);/*  www  . j  av a 2  s .  com*/
}

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();
    String function = "CREATE OR REPLACE FUNCTION myfuncout(x OUT VARCHAR) RETURN VARCHAR IS " + "BEGIN "
            + "x:= 'outvalue'; " + "RETURN 'a returned string'; " + "END;";
    stmt.executeUpdate(function);//from  w w  w.  j  a  v  a 2  s  .com

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = null;/*w  w w.  ja va  2s .com*/
    Properties info = new Properties();
    // info.put("proxy_type", "4"); // SSL Tunneling
    info.put("proxy_host", "[proxy host]");
    info.put("proxy_port", "[proxy port]");
    info.put("proxy_user", "[proxy user]");
    info.put("proxy_password", "[proxy password]");
    info.put("user", "[db user]");
    info.put("password", "[db pass word]");
    conn = DriverManager.getConnection("jdbc:mysql://[db host]/", info);

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("Select NOW()");
    rs.next();
    System.out.println("Data- " + rs.getString(1));
    rs.close();
    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);
    CallableStatement cs = connection.prepareCall("{call myproc}");
    cs.execute();/*  www. jav  a 2 s  . c o  m*/
}