#
需求:从学生表中查询出所有姓名和班级都相同的学生信息。
SQL:select distinct name,class,count(*) as recordcount from student group by name,class having count(*)>1;
将“终端服务配置”中的“授权模式”更改为“每用户”。为此,请按照下列步骤操作:
1.单击“开始”,“管理工具”,然后单击“终端服务配置”。
2.单击“服务器设置”,然后双击“授权模式”。
3.将“授权模式”更改为“每用户”,然后单击“确定”。
1.生成测试数据:
create table team(name varchar(32),person varchar(32));
insert into team values('A','Tom');
insert into team values('A','Jim');
insert into team values('A','Anny');
insert into team values('B','Ivy');
insert into team values('B','Henry');
insert into team values('C','Dar');
insert into team values('C','Rk');
insert into team values('D','Cenic');
select * from team;
2.创建合并团队成员姓名自定义函数:
create function fun_combName(@teamname varchar(32))
returns varchar(4000)
as
begin
declare @temp varchar(4000)
set @temp = ''
select @temp = @temp+';'+person from team where name = @teamname
set @temp = stuff(@temp,1,1,'')
return @temp
end
3.执行查询语句:
select name,person = dbo.fun_combName(name) from team group by name order by name;
注:测试完可以删除测试数据:
drop function fun_combName;
drop table team;
1.从最简单的做起,在最短的时间内完成最多的模块,把难点放到最后,这样可以使开发效率提高,对客户也好反馈;
2.不要去等待客户,尽自己所能去做,最后即使出现问题客户也说不出什么。
student:name,sex,age
score:name,subject,score
想要的结果:name,sex,age,sum(score)
1.
select s.name,s.sex,s.age,(select sum(c.score) from score c where c.name = s.name) from student s;
2.
select s.name,s.sex,s.age,sc.total from (select sum(c.score) as total,c.name
from score c group by c.name) sc inner join student s on s.name = sc.name;
jFreeChart是Java开发中常用的统计类组件,主要包括柱状图,饼状图等。下面我们介绍一下jFreeChart最简单的用法。
首先需要导入jFreeChart的jar包,放在项目web\WEB-INF\lib文件夹下。然后我们以最简洁的代码实现一个统计功能。
1.柱状图
import java.awt.Color;
import java.awt.Font;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
public class BarChartTest {
public static void main(String[] args) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(20, "企业备案数", "北京局");
dataset.addValue(18, "企业备案数", "上海局");
dataset.addValue(16, "企业备案数", "天津局");
dataset.addValue(15, "企业备案数", "重庆局");
dataset.addValue(45, "企业备案数", "山东局");
JFreeChart chart = ChartFactory.createBarChart("企业备案图", "直属局", "企业备案数",dataset, PlotOrientation.HORIZONTAL, true, false, false);
/** *//***************A start*********/
//设置标题字体样式
TextTitle textTitle = chart.getTitle();
textTitle.setFont(new Font("黑体", Font.PLAIN, 20));
//设置柱状体颜色
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
categoryplot.getRenderer().setSeriesPaint(0, new Color(228,109,10));
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
//设置X轴坐标上的字体样式
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
//设置X轴的标题字体样式
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
//设置Y轴坐标上的字体样式
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
//设置Y轴的标题字体样式
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
//设置图片最底部字体样式
if (chart.getLegend() != null) {
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
}
/** *//***************A end*********/
try {
ChartUtilities.writeChartAsPNG(new FileOutputStream("D:\\barChart.jpg"), chart, 400, 200);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
生成的文件显示效果如下:
2.饼状图
import java.awt.Color;
import java.awt.Font;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
public class PieChartTest {
public static void main(String[] args){
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("北京局",20);
pieDataset.setValue("上海局",18);
pieDataset.setValue("天津局",16);
pieDataset.setValue("重庆局",15);
pieDataset.setValue("山东局",45);
JFreeChart chart = ChartFactory.createPieChart3D("企业备案图",pieDataset, true, false, false);
/** *//***************A start*********/
//设置标题字体样式
chart.getTitle().setFont(new Font("黑体",Font.BOLD,20));
//设置饼状图里描述字体样式
PiePlot piePlot= (PiePlot) chart.getPlot();
piePlot.setLabelFont(new Font("黑体",Font.BOLD,10));
//设置显示百分比样式
piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(
("{0}({2})"), NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
//设置统计图背景
piePlot.setBackgroundPaint(Color.white);
//设置图片最底部字体样式
chart.getLegend().setItemFont(new Font("黑体",Font.BOLD,10));
/** *//***************A end*********/
try {
ChartUtilities.writeChartAsPNG(new FileOutputStream("D:\\pieChart.jpg"), chart, 400, 300);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
生成的文件显示效果如下:
其中以上两段代码中的“A”代码块中的内容是为了解决图片生成过程中遇到的乱码问题,在实际开发中可以写到一个公共类中,此时应注意服务器的操作系统上是否缺少上述代码中所用到的字体。关于jFreeChart详细参数的使用请参考官方文档。
今天去总局部署项目了,经历实在坎坷。上午一到那,值班人员是临时接替的,不熟悉机房的环境,找显示器,找键盘,插接口,慢慢开始适应环境。一切准备就绪,开始装系统,系统顺利的装完了,可配IP地址出问题了,找不到网络邻居的本地连接,打了N个电话,最后确认,网卡没有驱动起来,这就开始了寻找合适网卡的艰难历程,从11:30到16:30五个小时,终于在机房维护人员与HP客服的协助下成功装上驱动,一切正常了,离工作人员下班只有半小时了,赶紧开始装软件部署环境,oracle9i安装出错了,没时间查找错误原因,还好带了一套10g,换装oracle10g,服务器很快装好,但客户端配置出现了问题,一样来不及找原因,换sqldeveloper,导数据,启动服务,部署项目,天哪,终于搞定了!总结一下去机房部署要注意的事项:
1.带上一个以上笔记本电脑;
2.带上USB鼠标,最好还能有USB键盘,小型显示器;
3.带上一根以上网线;
4.带上圆口转USB接口的转接头;
5.提前想好一切有可能发生的事情。
简单总计一下今天的经历,呵呵。
Java web程序中备份oracle数据库
1.生成备份文件:
public ActionForward createDmp(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String fileName = "data_oracle" + sdf.format(c.getTime());
String dmpFolder = request.getSession().getServletContext()
.getRealPath("")
+ "\\datas\\dmp\\";
String logFolder = request.getSession().getServletContext()
.getRealPath("")
+ "\\datas\\log\\";
String cmd = "exp username/password@orcl file='" + dmpFolder + fileName
+ ".dmp' log='" + logFolder + fileName + ".log' owner=username";
Runtime.getRuntime().exec(cmd);
Thread.sleep(100 * 1000);
request.setAttribute("msg", "备份成功,文件生成会有延迟,请稍等");
return mapping.findForward("dmpCreated");
}
2.查询备份文件:
public ActionForward findDmp(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String dmpFolder = request.getSession().getServletContext()
.getRealPath("")
+ "\\datas\\dmp\\";
File folder = new File(dmpFolder);
File[] files = folder.listFiles();
List<String[]> fileList = new ArrayList<String[]>();
for (int i = 0; i < files.length; i++) {
if (files[i].getName().indexOf(".dmp") > 0) {
String[] one = new String[2];
one[0] = files[i].getName();
one[1] = files[i].length() / 1000 + "K";
fileList.add(one);
}
}
request.setAttribute("fileList", fileList);
return mapping.findForward("dmpList");
}
3.删除备份文件:
public ActionForward deleteDmp(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String dmpFolder = request.getSession().getServletContext()
.getRealPath("")
+ "\\datas\\dmp\\";
File folder = new File(dmpFolder);
File[] files = folder.listFiles();
String fileName = request.getParameter("dmpName");
for (int i = 0; i < files.length; i++) {
if (files[i].getName().equals(fileName)) {
files[i].delete();
request.setAttribute("msg", "删除成功");
break;
}
}
return mapping.findForward("dmpList");
}
|