123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package com.gyee;
- import net.coobird.thumbnailator.Thumbnails;
- import javax.imageio.ImageIO;
- import java.awt.geom.AffineTransform;
- import java.awt.image.AffineTransformOp;
- import java.awt.image.BufferedImage;
- import java.io.*;
- import java.sql.*;
- import java.util.*;
- public class SqlSeverTicket {
- public static void main(String []args) throws SQLException {
- String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
-
- String dbURL = "jdbc:sqlserver://10.155.32.2:1433;DatabaseName=fdeam";
-
- String userName = "sa";
- String userPwd = "Gyee@321#!";
- Connection conn = null;
- try {
- Class.forName(driverName);
- conn = DriverManager.getConnection(dbURL, userName, userPwd);
-
-
-
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- conn.close();
- }
- }
-
- public static Map<String, List> getLabor(Connection conn){
- Map<String, List> labors = new HashMap<>();
- try {
- PreparedStatement ps = conn.prepareStatement("select * from LABOR");
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- List<String> list = new ArrayList<>();
- String laborNum = rs.getString("LABORNUM");
- String laborName = rs.getString("LABORNAME");
- String deptNum = rs.getString("DEPTNUM");
- list.add(0, laborName);
- list.add(1, deptNum);
- labors.put(laborNum, list);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return labors;
- }
- public static List<String> getLabors(Connection conn){
- List<String> list = new ArrayList<>();
- try {
- PreparedStatement ps = conn.prepareStatement("select * from SIGNPICTURE");
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- String laborNum = rs.getString("LABORNUM");
- list.add(laborNum);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return list;
- }
-
- public static void setLabor(Connection conn, Map map) throws SQLException {
- List<String> lists = new ArrayList<>();
- try {
- PreparedStatement ps = conn.prepareStatement("select * from SIGNPICTURE");
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- String laborNum = rs.getString("LABORNUM");
- lists.add(laborNum);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement("Insert into SIGNPICTURE (LABORNUM,LABORNAME,DEPTNUM) values (?,?,?)");
- Iterator<Map.Entry<String, List>> entries = map.entrySet().iterator();
- while(entries.hasNext()){
- Map.Entry<String, List> entry = entries.next();
- String key = entry.getKey();
- if(!lists.contains(key))
- {
- List list = entry.getValue();
- ps.setString(1,key);
- ps.setString(2, String.valueOf(list.get(0)));
- ps.setString(3, String.valueOf(list.get(1)));
- ps.executeUpdate();
- }
- }
- ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- ps.close();
- }
- }
-
- public static void setImage(Connection conn, String filePath, String laborNum)
- {
- FileInputStream fis=null;
- File file = new File(filePath);
- try{
- fis = new FileInputStream(file);
- }catch(FileNotFoundException e){
-
- }
- try{
- PreparedStatement ps = conn.prepareStatement("update SIGNPICTURE set IMAGE = ? where LABORNUM = '"+laborNum+"'");
- ps.setBinaryStream(1,fis,(int)file.length());
- ps.executeUpdate();
- ps.close();
- fis.close();
-
- }catch(Exception e){
-
- }
- }
-
- private static void batchThumb(String filePath1, String filePath2){
- File file = new File(filePath1);
- File[] files = file.listFiles();
- if(files != null){
- for(int i = 0; i < files.length; i++){
- String fileName = files[i].getName();
- try {
- Thumbnails.of(filePath1 + fileName)
- .size(100, 40)
- .toFile(filePath2 + fileName);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- continue;
- }
- }
- }
- }
-
- private static void singleThumb(String filePath1, String filePath2, String fileName) throws IOException {
- Thumbnails.of(filePath1 + fileName)
- .size(100, 40)
- .toFile(filePath2 + fileName);
- }
- }
|