建图形化项目
SW—SWT Designer—SWT/JFace
SWT基本程序框架
1.数据库服务器:ojdbc14.jar
2.配置文件:db.propreties
driver_name= oracle. jdbc. driver. OracleDriver
url= jdbc: oracle: thin: @localhost : 1521 : orcl
user= scott
password= a
3.JUnit 4
1. 右击- Build Path - Add Libraries
2. 没有主函数
3. 选中方法名右击运行单个方法进行测试
4. 注解
@Test 方法可运行
@Ignore 方法运行时被忽略
@Before 方法执行前运行
@After 方法执行完运行
4.lib
存放第三方文件,如ojdbc14. jar
5.包结构
1. com. vc. ui:图形化界面
2. com. vc. dao:一张表对应一个dao(命名:表名DAO)
在此对每个表增删改查操作, 即写sql语句, 与数据库联系
3. com. vc. test:测试Dao 类中sql语句有无错误(命名:表名DAOTest )
4. com. vc. util:帮助类,存放封装的方法. . .
5. com. vc. commons:帮助文档
6. image:图
案例:添加图片到数据库
public int add ( byte [ ] bt) { . . . . return db. update ( bt) }
FileDialog fd = new FileDialog ( shell) ;
fd. setFilterPath ( "E:\\" ) ;
fd. setFilterExtensions ( new String [ ] { "*.jpg" , "*.png" , "*.gif" , "*.*" } ) ;
filePath= fd. open ( ) ;
if ( null == filePath|| "" . equals ( filePath) ) {
MessageDialog . openError ( shell, "警告⚠" , "未选中图片" ) ;
return ;
}
try {
File file = new File ( filePath) ;
InputStream in = new FileInputStream ( file) ;
Image image = new Image ( Display . getDefault ( ) , in) ;
label_image. setImage ( image) ;
label_tishi. setText ( "图片上传成功" ) ;
} catch ( Exception e1) {
e1. printStackTrace ( ) ;
}
File file = new File ( filePath) ;
InputStream in = new FileInputStream ( file) ;
byte [ ] bt= new byte [ ( int ) file. length ( ) ] ;
in. read ( bt) ;
int result = dao. add ( bt)
if ( result<= 0 ) {
YcUtil . showMessage ( shell, "错误提示" , "添加失败" ) ;
return ;
}