1. import java.sql.Connection; 
  2. import java.sql.DriverManager; 
  3. import java.sql.PreparedStatement; 
  4. import java.sql.ResultSet; 
  5. import java.sql.SQLException; 
  6. import java.sql.Statement; 
  7. import java.security.MessageDigest; 
  8. import java.security.NoSuchAlgorithmException; 
  9.  
  10. public class MD5_1 { 
  11.      public static String str; 
  12.      //public static String shu = "123456"; 
  13.       
  14.       public void md5s(String plainText) { 
  15.           try { 
  16.            MessageDigest md = MessageDigest.getInstance("MD5"); 
  17.            md.update(plainText.getBytes()); 
  18.            byte b[] = md.digest(); 
  19.  
  20.            int i; 
  21.  
  22.            StringBuffer buf = new StringBuffer(""); 
  23.            for (int offset = 0; offset < b.length; offset++) { 
  24.             i = b[offset]; 
  25.             if (i < 0
  26.              i += 256
  27.             if (i < 16
  28.              buf.append("0"); 
  29.             buf.append(Integer.toHexString(i)); 
  30.            } 
  31.            str = buf.toString(); 
  32.            System.out.println("result: " + buf.toString());// 32位的加密 
  33.            System.out.println("result: " + str.substring(824));// 16位的加密 
  34.           } catch (NoSuchAlgorithmException e) { 
  35.            // TODO Auto-generated catch block 
  36.            e.printStackTrace(); 
  37.  
  38.           } 
  39.          } 
  40.  
  41. //       public static void main(String agrs[]) {
     
  42. //        md5 md51 = new md5(); 
  43. //        md51.md5s("123456");//加密4 
  44. //       } 
  45.  
  46.      
  47.     public static void main(String[] args){ 
  48.         String shu = "admin"
  49.          
  50.         MD5_1 md51 = new MD5_1(); 
  51.         md51.md5s(shu); 
  52.          
  53.          
  54.            String url = "jdbc:mysql://localhost:3306/wh_viss"
  55.            String name = "root"
  56.            String password = "ccnu"
  57.            //String Username; 
  58.            Connection conn=null
  59.            PreparedStatement ps=null
  60.            Statement stmt=null
  61.            ResultSet rs=null
  62.            try {     
  63.             Class.forName("com.mysql.jdbc.Driver"); 
  64.             conn = DriverManager.getConnection(url,name,password); 
  65.             System.out.println("重置密码的数据库连接成功!"); 
  66.          ps = conn.prepareStatement("insert into users values(?,?,?,?)"); 
  67.          //md5 md51 = new md5(); 
  68.        //   InsertDB.md5s("123456");//加密4 
  69.          ps.setString(1,"5"); 
  70.          ps.setString(2,"zhangsan"); 
  71.          ps.setString(3,str.substring(824)); 
  72.          ps.setString(4,"zhangsan@qq.com"); 
  73.          //rs= ps.executeQuery();  
  74.          ps.executeUpdate(); 
  75. //      ps = conn.prepareStatement("select * from user"); 
  76. //           
  77. //      rs= ps.executeQuery();  
  78. //         
  79.                 
  80.  
  81.            } catch (ClassNotFoundException e) { 
  82.             e.printStackTrace(); 
  83.     System.out.println("数据库链接失败1");      
  84.           }catch(SQLException e){ 
  85.               e.printStackTrace(); 
  86.     System.out.println("数据库链接失败2");            
  87.           }finally
  88.               try {   
  89.               if(rs!=null){ 
  90.                   rs.close(); 
  91.               } 
  92.               if(ps!=null){ 
  93.                   ps.close(); 
  94.               } 
  95.               if(conn!=null){ 
  96.                   conn.close(); 
  97.               } 
  98.              }catch (SQLException e) { 
  99.                     e.printStackTrace(); 
  100.             } 
  101.           } 
  102.           //return Username; 
  103.            
  104.  
  105.          
  106.          
  107.         System.out.println("调用了重置页面!"); 
  108.          
  109.          
  110.        } 
  111.      
  112.