/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db;
import java.sql.*;
/**
*
* @author subinsuresh
*/
public class dbconnection {
Statement stmt;
Connection con;
public void start() {
try {
ResultSet rs;
//Register the JDBC driver for Oracle.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
/*
* Define URL of database server for database on the localhost
* with the default port number 1521.
*/
String url = "jdbc:oracle:thin:@localhost:1521:serviceID";
/*
* Get a connection to the database for a user named root with the password
* subin
*/
con = DriverManager.getConnection(url, "root", "subin");
//Display URL and connection information
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
//Get a Statement object
stmt = con.createStatement();
//Query the database, storing the result in an object of type ResultSet
rs = stmt.executeQuery("SELECT * from tablename");
} catch (Exception e) {
e.printStackTrace();
}//end catch
}
public Statement getstatement() throws SQLException {
stmt=con.createStatement();
return stmt;
}
}
Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts
Tuesday, August 31, 2010
Monday, August 16, 2010
Creating users for Oracle
Create User
SQL> CREATE SUBIN(USERNAME)IDENTIFIED BY SUBIN(PASSWORD);
User created.
SQL> GRANT CONNECT, RESOURCE,DBA to SUBIN
(USERNAME)
;
Grant succeeded.
Commit
SQL> COMMIT;
Labels:
Oracle
Subscribe to:
Posts (Atom)