public static Connection getCon() { Connection conn=null; try { //2005连接方法 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); conn = DriverManager .getConnection("jdbc:sqlserver://localhost;username=sa;password=;DatabaseName=DB_Shop"); } catch (Exception ex) { ex.printStackTrace(); } return conn; } private Connection conn = null; private Statement stmt = null; private ResultSet rs = null; private String sql = null; private boolean b = false; public Collection<LiuVo> c = null; private ArrayList<LiuVo> list = null; private PreparedStatement pstmt = null; private LiuVo liuvo = null; private int i=0; /** * 查询不重复的类型 * * @return */ public Collection select_distinct_type() { try { sql = "select distinct(types) from userinfo"; stmt = DB.getConnection().createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { list = new ArrayList<LiuVo>(); do { liuvo = new LiuVo(); liuvo.setType(rs.getString(1)); list.add(liuvo); } while (rs.next()); } } catch (Exception ex) { } return list; } /** * 修改 * * @return */ public int update_result(String id ,String result) { sql = "update userinfoset results='"+result+" 'where ids="+id; System.out.println(sql); try{ pstmt= DB.getConnection().prepareStatement(sql); i=pstmt.executeUpdate(); }catch(Exception ex){ ex.printStackTrace(); } return i; } /** * 添加 * * @return */ public boolean add(LiuVo vo) { sql = "INSERT INTO userinfo( numbers, names, types, contexts,remark) VALUES (?,?,?,?,?)"; try { pstmt = DB.getConnection().prepareStatement(sql); pstmt.setString(1, vo.getNumber()); pstmt.setString(2, vo.getName()); pstmt.setString(3, vo.getType()); pstmt.setString(4, vo.getContext()); pstmt.setString(5, vo.getRemark()); int i = pstmt.executeUpdate(); if (i > 0) { b = true; } } catch (Exception ex) { ex.printStackTrace(); } finally { if (pstmt != null) try { pstmt.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return b; }