基本信息
源码名称:java Swing编程计算器,实现对数据库访问(sqlserver)
源码大小:0.78M
文件格式:.rar
开发语言:Java
更新时间:2016-03-28
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
通过数据库的存储数据,用到了 Sql-Server-2_fat.jar
通过数据库的存储数据,用到了 Sql-Server-2_fat.jar
package eyou.dt; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.sql.*; import java.util.Properties; public class DBUtils { private PreparedStatement p; private String spring; private String Type; private String summer; private String fall; private String winter; private static ResultSet rs; private static FileInputStream stat; private static Object conn; private static Object P; static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; private static String url; private static String user; private static String pwd; public static Connection getConnection() { Connection con = null; try { Class.forName(DRIVER); Properties property = new Properties(); try { property.load(new FileInputStream("message.properties")); url = property.getProperty("url"); user = property.getProperty("user"); pwd = property.getProperty("pwd"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } con = DriverManager.getConnection(url, user, pwd); } catch (ClassNotFoundException e) { System.out.println("连接失败"); e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return con; } // ���� public static void close(Connection conn) { if (conn != null) {// �����ָ���쳣 try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } } public static void main(String[] args) { DBUtils d=new DBUtils(); try { d.findByFall(); d.findBySpring(); d.findBySummer(); d.findByWinter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 在读取出来 * * @return * @throws IOException */ public boolean findBySpring() throws IOException {// SELECT // IssueUserNo,Pic Boolean picType = false; // FROM // T_BgGraph // where PicID=1 /eyou/ui/image/ String sql = "select Top 1 * from T_BgGraph WHERE TYPE=0 AND ImageShow=1 order by UpdTime desc"; Connection conn = null; conn = DBUtils.getConnection(); try { p = conn.prepareStatement(sql); rs = p.executeQuery(); //根据路径来 实现图片 Properties property = new Properties(); try { property.load(new FileInputStream("message.properties")); spring = property.getProperty("Spring"); Type=property.getProperty("PicType"); } catch (IOException e) { e.printStackTrace(); } while (rs.next()) { FileOutputStream newFile = new FileOutputStream("D:/java/EYouDemo/src/eyou/ui/image/" spring Type); Filte(newFile); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeCon(); } return picType; } public boolean findBySummer() throws IOException {// SELECT // IssueUserNo,Pic Boolean picType = false; // FROM // T_BgGraph // where PicID=1 /eyou/ui/image/ String sql = "select Top 1 * from T_BgGraph WHERE TYPE=0 AND ImageShow=2 order by UpdTime desc"; Connection conn = null; conn = DBUtils.getConnection(); try { p = conn.prepareStatement(sql); rs = p.executeQuery(); //根据路径来 实现图片 Properties property = new Properties(); try { property.load(new FileInputStream("message.properties")); summer = property.getProperty("summer"); Type=property.getProperty("PicType"); } catch (IOException e) { e.printStackTrace(); } while (rs.next()) { FileOutputStream newFile = new FileOutputStream("D:/java/EYouDemo/src/eyou/ui/image/" summer Type); Filte(newFile); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeCon(); } return picType; } public boolean findByFall() throws IOException {// SELECT // IssueUserNo,Pic Boolean picType = false; // FROM // T_BgGraph // where PicID=1 /eyou/ui/image/ String sql = "select Top 1 * from T_BgGraph WHERE TYPE=0 AND ImageShow=3 order by UpdTime desc"; Connection conn = null; conn = DBUtils.getConnection(); try { p = conn.prepareStatement(sql); rs = p.executeQuery(); //根据路径来 实现图片 Properties property = new Properties(); try { property.load(new FileInputStream("message.properties")); fall = property.getProperty("fall"); Type=property.getProperty("PicType"); } catch (IOException e) { e.printStackTrace(); } while (rs.next()) { FileOutputStream newFile = new FileOutputStream("D:/java/EYouDemo/src/eyou/ui/image/" fall Type); Filte(newFile); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeCon(); } return picType; } public boolean findByWinter() throws IOException {// SELECT // IssueUserNo,Pic Boolean picType = false; // FROM // T_BgGraph // where PicID=1 /eyou/ui/image/ String sql = "select Top 1 * from T_BgGraph WHERE TYPE=0 AND ImageShow=4 order by UpdTime desc"; Connection conn = null; conn = DBUtils.getConnection(); try { p = conn.prepareStatement(sql); rs = p.executeQuery(); //根据路径来 实现图片 Properties property = new Properties(); try { property.load(new FileInputStream("message.properties")); winter = property.getProperty("winter"); Type=property.getProperty("PicType"); } catch (IOException e) { e.printStackTrace(); } while (rs.next()) { FileOutputStream newFile = new FileOutputStream("D:/java/EYouDemo/src/eyou/ui/image/" winter Type); Filte(newFile); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtils.closeCon(); } return picType; } //封装读取的方法 public void Filte(FileOutputStream newFile) throws SQLException, IOException { InputStream image = rs.getBinaryStream("Pic"); // 读取 String len = image.toString(); long length = len.length(); byte[] buffer = new byte[(int) length / 7]; // 定义 // buffer为缓冲区每次读取内容的长度 try { // 将文件写进去 int readSize; while ((readSize = image.read(buffer)) != -1) { newFile.write(buffer, 0, readSize); } } catch (Exception e) { // TODO: handle exception } finally { image.close(); newFile.close(); } } public static void closeCon() throws IOException { // 关闭的方法 try { if (rs != null) { rs.close(); rs = null; } if (P != null) { ((FileInputStream) P).close(); P = null; } if (conn != null) { ((FileInputStream) conn).close(); conn = null; } } catch (SQLException e) { e.printStackTrace(); } } }