This is my blog
by
因特网 -> Apche Tomcat -> web.xml -> FirshServlet
FirshServlet -> 用户
Servlet默认情况下是第一次访问的时候实例化,也可以通过web.xml配置load-on-startup,使其在服务器启动的时候实例化。
Tomcat全局中,有且仅有唯一的一个对象。 — Servlet在并发环境下,是单例多线程,在多线程下,所有线程共享一个Servlet实例,不允许创建存在状态的变量或对象,造成无法预期的结果。
request.getRequestDispatcher().forward()
response.sendRedirect()
内置对象 | 描述 |
---|---|
request | 请求对象 - HttpServletRequest |
response | 响应对象 - HttpServletResponse |
session | 用户会话 - HttpSession |
application | 应用全局对象 - ServletContext |
out | 输出对象 - PrintWriter |
page | 当前页面对象 - this |
pageContext | 页面上下文对象 - PageConetxt |
config | 应用配置对象 - ServletConfig |
exception | 应用异常对象 - Throwable |
package com.imooc.interview.jdbc;
import java.sql.*;
public class MysqlJDBC {
public static void main(String[] args) {
String driverName = "com.mysql.jdbc.Driver";
String URL = "jdbc:mysql://127.0.0.1:3306/scott";
String sql = "SELECT * FROM emp";
String username = "root";
String password = "root";
Connection conn = null;
try {
//1.加载JDBC驱动
Class.forName(driverName);
//2.建立连接
conn = DriverManager.getConnection(URL, username, password);
//3.创建命令(Statement)
Statement ps = conn.createStatement();
//4.处理结果
ResultSet rs = ps.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getString("ename") + "," +
rs.getString("job") + "," +
rs.getFloat("sal"));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
//5.关闭连接
finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
select
*
from emp
order by deptno asc,sal desc;
select
d.dname,e.*
from emp e left join dept d on e.deptno=d.deptno
where e.deptno=30;
select
d.dname,e.*
from emp e,dept d
where e.deptno=d.deptno and e.deptno=30;
select
deptno,
max(sal) as maxSal,
min(sal) as minSal,
avg(sal) as avgSal,
count(*)
from emp
group by deptno;
select
d.dname,e.*
from emp e,dept d
where e.deptno=d.deptno and (d.dname='RESEARCH' or d.dname='SALES');
select
d.dname,count(*) num
from emp e,dept d
where e.deptno=d.deptno
group by d.dname having num>3;
select
a.a_sal,b.b_sal,a.a_sal-b.b_sal
from
(select sal * 12 a_sal from emp where ename='MILLER') a,
(select sal * 12 b_sal from emp where ename='SMITH') b;
select *
from emp
where mgr = (select empno from emp where ename='KING');
select e.*
from emp e, (select empno from emp where ename='KING') k
where e.mgr=k.empno;
select date_format(now(),"%Y%m%d");
select * from (
select emp.*, date_format(now(),"%Y")-date_format(hiredate,"%Y") yg
from emp
) d
order by d.yg desc;
select
a.a_avg-b.b_avg
from
(select avg(sal) a_avg from emp where job='MANAGER' or job='PRESIDENT') a,
(select avg(sal) b_avg from emp where job in ('CLERK','SALESMAN','ANALYST')) b;