SELECT TO_DATE('12-3月-04') FROM dual;
select * from dept for update;
update dept t set t.dept_time=to_date('2013-01-13','yyyy-mm-dd') where t.deptno='10';
SELECT * FROM NLS_DATABASE_PARAMETERS
select * from nls_session_parameter;ggggggggggggggggggggggggggggggggggggggggggg
--有空值 count(列) count(*)不一样
select count(t.dname) from dept t ;
select count(*) from dept;
select * from dept;
--查询当前用户信息
select user from dual;
connect tt/tt11;
SELECT * FROM NLS_DATABASE_PARAMETERS;
select * from emp for update;
--分组统计男女
select sum(decode(sex,'男',1,0)) 男人数,sum(decode(sex,'女',1,0)) 女人数 from emp;
select * from abc;
--nvl系统函数处理空值
select deptno, nvl(dname,'未输入')from dept;
select * from dept t where t.dname is null;
select * from dept t where t.dname=null;--判断为空错误写法
select * from dept t order by t.deptno asc;
select * from dept t order by t.deptno desc;
select * from dept t for update;
select distinct loc from dept;
select empno, ename, job, mgr, hiredate, sal, comm, deptno, sex from emp;
select (t.deptno*sal) from emp t;
--分组查询
select sex ,count(sex) from emp group by sex having count(sex)>1;
--模糊查询 1981年雇佣的员工
select * from emp t where t.hiredate like '1981%';--日期类型无法模糊
--模糊查询销售员工
select * from emp t where t.job like 'CLE%';
--表的链接 部门和员工
select * from emp e ;--for update;
select * from dept d --for update;
select e.empno 员工编号,d.deptno 部门编号 from emp e ,dept d
where e.deptno = d.deptno;
--内连接
select e.empno 员工编号,e.sex 性别,d.dname 所在部门 from emp e join dept d
on e.deptno = d.deptno;
--外连接不完全匹配 --左连接
select e.empno 员工编号,e.ename 姓名 ,e.sex 性别,d.dname 所在部门 from emp e join dept d
on e.deptno = d.deptno(+);
select e.empno 员工编号,e.ename 姓名 ,e.sex 性别,d.dname 所在部门 from emp e join dept d
on e.deptno(+) = d.deptno;
--子查询
select * from emp e where e.deptno in (select d.deptno from dept d);
select * from emp where exists (select e.empno from emp e where e.empno=22);
select * from emp where exists (select * from dept where dept.deptno=emp.deptno);
--union 使用
select deptno from emp union
select deptno from dept;
--intersect
select deptno from emp intersect
select deptno from dept;
--插入结果集
insert into emp(empno,ename) select deptno,dname from dept;
create table ttt as (select * from emp);
select * from ttt;
--视图
1、Oracle8/8i/9i/10i数据库(thin模式)
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
2、DB2数据库
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名
String user="admin";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
3、Sql Server7.0/2000数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb为数据库
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
ibatis连接oracle异常:
java.sql.SQLException: Io 异常: NL Exception was generated
百度可能是连接url的问题:
4、Sybase数据库
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);
5、Informix数据库
Class.forName("com.informix.jdbc.IfxDriver").newInstance();
String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword"; //myDB为数据库名
Connection conn= DriverManager.getConnection(url);
6、MySQL数据库
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
//myDB为数据库名
Connection conn= DriverManager.getConnection(url);
7、PostgreSQL数据库
Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);
8、access数据库直连用ODBC的
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");
Connection conn = DriverManager.getConnection(url,"","");
Statement stmtNew=conn.createStatement() ;
查看oracle连接的url
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=flight)(SERVER=DEDICATED))";
复制到myeclipse java类文件中查看少了一个)晕,复制的问题:
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=flight)(SERVER=DEDICATED)))