解锁用户名:如(scott)
alter user 用户名 account unlock identified by 密码
修改用户密码:
alter user 用户名 identified by 密码
新建tablespace:
create tablespace practice
datafile 'F:/oracle/liuyong.dbf'
size 10M
autoextend on next 32M maxsize unlimitied // 文件可自动扩展,每次自动扩展32M
extent management local // 表空间中的盘区采用本地化管理方式
segment space management auto // 表空间中段的管理方式为自动化管理方式
新建用户:
create user liuyong
identified by liuyong // 密码
default tablespace practice /// 默认的表空间
给用户赋权限
grant connect ,resource to liuyong // 把connect,resource角色授予用户liuyong
撤销权限
revoke connect from liuyong
方法一:(需将驱动.jar包拷贝到项目目录下)
Class.forName("oracle.jdbc.driver.OracleDriver"); // 加载驱动
Connection conn = DriverManaer.getConnection( "jdbc:oracle:thin:@localhost:1521:oracle" );
方法二:(连接池)
1、修改服务器的配置文件context.xml(同样需要将驱动包拷贝到服务器的lib文件夹下)
<Resource name="jndi/yituan" auth="Container"
type="javax.sql.DataSource" username="liuyong" password="liuyong"
url="jdbc:oracle:thin:@localhost:1521:oracle"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxActive="100" maxIdle="10"
maxWait="1000"
/>
2.代码部分
eg:
public BaseDao{
Context ctxt = null;
DataSource ds = null;
Connection conn = null;
public BaseDao(){
try{
ctxt = new InitialContext();
ds = (DataSource) ctxt.lookup("java:comp/env/jndi/yituan");
} catch (Exception e){
e.printStackTrace();
}
}
// 获取连接
public Connection getConn(){
try{
conn = ds.getConnection();
} catch (Exception e){
e.printStackTrace();
}
}
// 释放连接
public void closeConn(Connection conn , PreparedStatement ptmt , ResultSet rs ){
try{
if(rs != null){
rs.close();
}
ptmt.close();
conn.close();
}
}
}