how2j.cn


工具版本兼容问题
学习了这么多J2SE基础和中级的知识点,接下来就需要一个综合性的项目把这些的知识点都融会贯通

本项目是基于Swing和JDBC开发的图形界面桌面应用,涵盖了J2SE的绝大部分基础知识,通过这个项目能运用和锻炼几乎大部分的J2SE知识和技能。

涉及到如下内容:
基础内容:
面向对象 字符串数字 日期

中级内容:
异常 ,集合,JDBC, 反射机制,I/O,Swing, 利用TableModel更新数据, 图形界面的皮肤

高级内容:
图表chart动态生成,数据库的备份与恢复,自定义圆形进度条

软件设计思想:
单例模式,面板类与监听器类松耦合,Entity层设计,DAO层设计,Service层设计

业务常见处理手法:
CRUD操作,配置信息,配置信息初始化,报表生成,一对多关系,多对一关系

通过本项目,积累宝贵的项目经验,在面试的时候,多一项谈资多一层砝码多一些薪水


18分18秒
本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)




HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


最近10个提问
2018-05-01 不清楚把Statement改成PrepareStatement后成功的原因
Java66



做项目的时候,在设置页面中,tfBudget和tfMysqlPath中不能显示出数据库中的值 而且会报错 这是为什么?详情看图
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import Util.DBUtil;
import entity.Config;

public class ConfigDAO {

	public int getTotal() {
		int total=0;
		try (Connection c=DBUtil.getConnection();
				Statement s=c.createStatement();){
			String sql="select * from config";
			ResultSet rs=s.executeQuery(sql);
			while(rs.next()) {
				total=rs.getInt(1);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return total;
	}
	public void add(Config config) {
		String sql="insert into config values(null,?,?)";
		try (
			Connection c=DBUtil.getConnection();
				PreparedStatement ps=c.prepareStatement(sql);){
			
			ps.setString(1, config.key);
			ps.setString(2, config.value);
			ps.execute();
			ResultSet rs=ps.getGeneratedKeys();
			if(rs.next())
			{
				int id=rs.getInt(1);
				config.id=id;
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	public static void update(Config config) {
		String sql="update config set key_=?,value=? where id=?";
		try (Connection c=DBUtil.getConnection();
				PreparedStatement ps=c.prepareStatement(sql);){
			ps.setString(1, config.key);
			ps.setString(2, config.value);
			ps.setInt(3, config.id);
			ps.execute();
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	public void delete(int id) {
		String sql="delete * from config where id="+id;
		try (Connection c=DBUtil.getConnection();
				Statement s=c.createStatement();){
			s.execute(sql);
	
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	
	public Config get(int id) {
		Config config=null;
		String sql="select * from config where id="+id;
		try (Connection c=DBUtil.getConnection();
				Statement s=c.createStatement();){
			ResultSet rs=s.executeQuery(sql);
			if(rs.next())
			{
				config=new Config();
				String key=rs.getString("key_");
				String value=rs.getString("value");
				config.key=key;
				config.value=value;
			}
		
		} catch (Exception e) {
			// TODO: handle exception
		}
		return config;
	}
	
	public List<Config> list(){
		return list(0,Short.MAX_VALUE);
	}
	public List<Config> list(int start,int count){
		List<Config> configs=new ArrayList<>();
		String sql="select * from config order by id desc limit ?,?";
		try (Connection c=DBUtil.getConnection();
				PreparedStatement ps=c.prepareStatement(sql)){
			ps.setInt(1, start);
			ps.setInt(2, count);
			ResultSet rs=ps.executeQuery();
			while(rs.next()){
				Config config=new Config();
				int id=rs.getInt("id");
				String key=rs.getString("key_");
				String value=rs.getString("value");
				config.key=key;
				config.value=value;
				config.id=id;
				configs.add(config);
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return configs;
	}
	public Config getByKey(String key) {
		Config config=null;
		String sql="select * from config where key_=?";
		try (Connection c=DBUtil.getConnection();
				PreparedStatement ps=c.prepareStatement(sql);){//!!!!!!!!!!!!!!!!!
			ps.setString(1, key);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!为什么这里不能用statement
			ResultSet rs=ps.executeQuery();
			if(rs.next())
			{
				config=new Config();
				int id=rs.getInt("id");
				String value=rs.getString("value");
				config.id=id;
				config.key=key;
				config.value=value;
			}	
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return config;
	}
	
	
}
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'budget' in 'where clause'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
	at com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
	at dao.ConfigDAO.getByKey(ConfigDAO.java:132)
	at service.ConfigService.init(ConfigService.java:23)
	at service.ConfigService.init(ConfigService.java:17)
	at service.ConfigService.<clinit>(ConfigService.java:13)
	at gui.panel.ConfigPanel.updateData(ConfigPanel.java:67)
	at Util.CenterPanel.show(CenterPanel.java:53)
	at gui.listener.ToolBarListener.actionPerformed(ToolBarListener.java:27)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'mysqlPath' in 'where clause'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
	at com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
	at dao.ConfigDAO.getByKey(ConfigDAO.java:132)
	at service.ConfigService.init(ConfigService.java:23)
	at service.ConfigService.init(ConfigService.java:18)
	at service.ConfigService.<clinit>(ConfigService.java:13)
	at gui.panel.ConfigPanel.updateData(ConfigPanel.java:67)
	at Util.CenterPanel.show(CenterPanel.java:53)
	at gui.listener.ToolBarListener.actionPerformed(ToolBarListener.java:27)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'budget' in 'where clause'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
	at com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
	at dao.ConfigDAO.getByKey(ConfigDAO.java:132)
	at service.ConfigService.get(ConfigService.java:33)
	at gui.panel.ConfigPanel.updateData(ConfigPanel.java:67)
	at Util.CenterPanel.show(CenterPanel.java:53)
	at gui.listener.ToolBarListener.actionPerformed(ToolBarListener.java:27)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at service.ConfigService.get(ConfigService.java:34)
	at gui.panel.ConfigPanel.updateData(ConfigPanel.java:67)
	at Util.CenterPanel.show(CenterPanel.java:53)
	at gui.listener.ToolBarListener.actionPerformed(ToolBarListener.java:27)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)


5 个答案

Java66 答案时间:2018-05-03
我找到了哟! 字符串要用单引号括起来 我String sql="select * from config where key_="+key;是错误的 正确的应该还要加上单引号,String sql="select * from config where key_='"+key+"'"; 学艺不精还需努力o(╥﹏╥)o

Java66 答案时间:2018-05-03
好的 0.0

how2j 答案时间:2018-05-03
你写错SQL语句了,哎,抄都要抄错啊! “答案“ 都给你了,请比较我是怎么写的。 你这样,用diffmerge软件,进行文件夹比较。把你自己做的项目文件夹,和我的可运行项目文件夹进行比较 这个软件很牛逼的,可以知道文件夹里哪两个文件不对,而且很明显地标记出来 我这里就有下载和教程: http://how2j.cn/k/18/18-1583/1583.html

Java66 答案时间:2018-05-02
啊?我懵了,sql语句都是一样的为什么要检查config表有没有budget字段啊?? config表字段只有 id, key_ ,value

how2j 答案时间:2018-05-02
Unknown column 'budget' 这表示你的数据库的表没有 budget 这个字段哟




答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2018-04-29 有个问题
小白王
swing现在不是都过时了吗




2 个答案

漂洋过海的猪 答案时间:2018-05-03
用swing做出来的东西客户不买账的原因是要依赖jdk.太过麻烦,所以c居多,但是对于开发者而言显然没有这个问题,所以做做自己用的小工具还是不错的 。不过swing的一大部分内容要在jdk中砍掉了 ,以后真的是用的越来越少了

how2j 答案时间:2018-04-30
并未过时,但是工作中用得少。 用得少,并不等于它没有用处,实际上我个人在工作中倒是经常使用,自己做些提高工作效率的小工具还是很有意思。 看个人喜好,时间有限,也可以跳过。




答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2018-04-23 下面同学要的截图
2018-04-23 上个问题中要求的截图
2018-04-20 我装MySQL在linux上
2018-04-20 关于视频清晰度的问题
2018-04-18 我很晕
2018-04-17 项目呢
2018-04-15 我没有明白checkempty ,checknumber,checkzero,之间true 和 false之间的代码逻辑,请站长讲一下qwq
2018-04-15 能不能提供 linux 的版本?




提问之前请登陆
关于 实践项目-一本糊涂账-项目简介 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 620943819
站长会在每个工作日早上尽量回答提问(如果有漏掉没有回答的,请进群提醒一下)
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
站长是玻璃心,提问的时候请语气温柔些 kiss~
截止2017-5-19日累计提问 1638个,站长回答了 1546个
截止2017-8-15日累计提问 2788个,站长回答了 2544个

上传截图