资源简介
该项目采用model2开发模式,将项目分为界面层、业务层、数据访问层、数据库层,下层为上层提供服务。实现对用户登陆验证、新闻查询、添加新闻、安全退出等功能!
代码片段和文件信息
package com.xwj.dao;
import java.io.*;
import java.sql.*;
import java.util.*;
public class SqlHelper {
//定义操作数据库所需变量
private static Connection ct=null;
private static PreparedStatement ps=null;
private static CallableStatement cs=null; //存储过程
private static ResultSet rs=null;
//定义所需参数
private static String driver; //驱动名
private static String url; //URL地址
private static String user; //用户名
private static String password; //密码
private static Properties pp=null;
private static FileInputStream fis=null;
public static Connection getCt() {
return ct;
}
public static PreparedStatement getPs() {
return ps;
}
public static ResultSet getRs() {
return rs;
}
static{
pp=new Properties();
try {
fis=new FileInputStream(“dbInfo.properties“);
pp.load(fis);
driver=pp.getProperty(“driver“);
url=pp.getProperty(“url“);
user=pp.getProperty(“user“);
password=pp.getProperty(“password“);
//加载驱动
Class.forName(driver);
} catch (Exception e) {
e.printStackTrace();
}finally{
//关闭资源
if(fis!=null){
try {
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
fis=null;
}
}
//得到连接
public static Connection getConnection(){
try {
ct=DriverManager.getConnection(url user password);
} catch (Exception e) {
e.printStackTrace();
}
return ct;
}
//执行更新操作(insert、delete、update)
//单条sql语句的执行
public static void executeUpdate(String sqlString[] parameters){
try {
ct=getConnection();
ps=ct.prepareStatement(sql);
if(parameters!=null){
for(int i=0;i ps.setString(i+1parameters[i]);
}
}
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
//抛出运行时异常
throw new RuntimeException(e.getMessage());
}finally{
close(ct ps rs);
}
}
//执行更新操作(insert、delete、update)
//多条sql语句的同时执行
public static void executeUpdate2(String[] sqlString[][] parameters){
try {
//1、得到连接
ct=getConnection();
//设置事务自动提交为false
ct.setAutoCommit(false);
for(int i=0;i ps=ct.prepareStatement(sql[i]);
if(parameters[i]!=null){
for(int j=0;j ps.setString(j+1parameters[i][j]);
}
}
ps.executeUpdate();
}
ct.commit();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}finally{
//关闭资源
close(ct ps rs);
}
}
//执行查询操作(select)
public static ResultSet executeQuery(String sqlString[] parameter){
try {
ct=getConnection();
ps=ct.prepareStatement(sql);
if(parameter!=null){
for(int i=0;i ps.setString(i+1parameter[i]);
}
}
rs=ps.executeQuery();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}finally{
//关闭资源
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 355 2017-03-28 20:59 新闻管理系统model2模式\newsSystemModel2\.classpath
文件 392 2017-03-27 11:41 新闻管理系统model2模式\newsSystemModel2\.project
文件 629 2017-03-27 11:41 新闻管理系统model2模式\newsSystemModel2\.settings\org.eclipse.jdt.core.prefs
文件 5296 2017-03-28 20:59 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\dao\SqlHelper.class
文件 1134 2017-03-28 20:59 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\domain\News.class
文件 1283 2017-03-28 21:19 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\domain\Users.class
文件 3540 2017-03-28 21:11 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\service\NewsService.class
文件 1408 2017-03-28 21:25 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\service\UsersService.class
文件 3291 2017-03-28 21:28 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\view\SystemNews.class
文件 120 2017-03-26 14:10 新闻管理系统model2模式\newsSystemModel2\dbInfo.properties
文件 1536554 2017-03-24 09:48 新闻管理系统model2模式\newsSystemModel2\lib\ojdbc14.jar
文件 4836 2017-03-27 11:43 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\dao\SqlHelper.java
文件 704 2017-03-27 11:47 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\domain\News.java
文件 750 2017-03-28 21:19 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\domain\Users.java
文件 2040 2017-03-28 21:11 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\service\NewsService.java
文件 627 2017-03-28 21:25 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\service\UsersService.java
文件 2289 2017-03-28 21:28 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\view\SystemNews.java
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\dao
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\domain
目录 0 2017-03-28 20:59 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\junit
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\service
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj\view
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\dao
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\domain
目录 0 2017-03-27 11:43 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\junit
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\service
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\src\com\xwj\view
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\bin\com\xwj
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\src\com\xwj
目录 0 2017-03-28 21:35 新闻管理系统model2模式\newsSystemModel2\bin\com
............此处省略11个文件信息
评论
共有 条评论