如何更新表中的数据?

时间:2015-11-05 12:54:03

标签: java

我完成了加密程序加密文本并试图应用此程序来加密数据库表中的字段。我有一个问题,即所有数据字段都是按值加密(最后一条记录)

public static void main(String[] args) throws IOException {
    String v_url = "jdbc:oracle:thin:@192.168.2.154:1522:orcl2";
    String v_username = "scott";
    String v_password = "tiger";
    Connection con = null;
    try {
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        con = DriverManager.getConnection(v_url, v_username, v_password);
        System.out
                .println("Connection to Oracle database  was Established");
        String sql = "select JOB_NAME  from job  ";
        Statement stmt = con.createStatement();
        ResultSet srs = stmt.executeQuery(sql);
        while (srs.next()) {
            vname = srs.getString("job_name");
        }
    } catch (SQLException err) {
        System.out.println(err.getMessage());
    }
    Scanner in = new Scanner(System.in);
    System.out.println("Enter Your KeyText ");
    String StrKey = in.nextLine();
    // Print the Concatenated Data.

    String ConcatenatedData = StrKey.concat(vname);
    System.out.println("The plaintext Data is : " + ConcatenatedData);

    // Convering the Concatenated data to Ascii data.
    byte[] asciiText = null;
    try {
        // translating text String to 7 bit ASCII encoding
        asciiText = ConcatenatedData.getBytes("US-ASCII");
        // System.out.println(Arrays.toString(asciiText));
    } catch (java.io.UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    String binary = "";
    for (byte b : asciiText) {
        // binary = Integer.toBinaryString(b & 255 | 256).substring(1);
        binary += Integer.toBinaryString(0x100 + (int) (b & 0xFF)).substring(1);
    }
    // System.out.println("Requested binary :" +binary);
    String ReversedBinary = binary.replace('0', '2').replace('1', '0').replace('2', '1');
    // System.out.println("Reveresd binary :" + ReversedBinary);
    mainencdec decimalToBinary = new mainencdec();
    String binary1 = decimalToBinary.convertBinaryStringToString(ReversedBinary);

    try {
        String sql_statment = "UPDATE job  SET job_name =?";
        PreparedStatement updatequery = con.prepareStatement(sql_statment);
        updatequery.setString(1, binary1);
        updatequery.executeQuery();
        con.commit();
        System.out.println("An existing user was updated successfully!");
    } catch (SQLException err) {
        System.out.println(err.getMessage());
    }

} 

问题是作业名称字段中的数据加密的值相同:JOB_NAME

323130,2'2$1'2&0&2#1
323130,2'2$1'2&0&2#1
323130,2'2$1'2&0&2#1
323130,2'2$1'2&0&2#1
323130,2'2$1'2&0&2#1

我希望此字段中的每个值都根据其数据加密

0 个答案:

没有答案