AES_ENCRYPT与mysql服务器5.5

时间:2016-11-07 12:09:53

标签: java mysql encryption jdbc

我正在尝试使用预准备语句以加密格式将数据插入MySQL。但是我收到了这个错误。我认为我的查询是正确的。

    Connection con=null;
    PreparedStatement psmt1=null;

    String tit=request.getParameter("tit");
    String min=request.getParameter("minvalue");
    String max=request.getParameter("maxvalue");
   String disc=request.getParameter("disc");
    System.out.println(tit);
    String [] title=tit.split(":");

   try{
   con=databasecon.getconnection();
  psmt1=con.prepareStatement("insert into medication(tid,titname,minvalue,maxvalue,disc) values(AES_ENCRYPT(?, 'key'),AES_ENCRYPT(?, 'key'),AES_ENCRYPT(?, 'key'),AES_ENCRYPT(?, 'key'),AES_ENCRYPT(?, 'key'))");

psmt1.setString(1,title[0]);
psmt1.setString(2,title[1]);
psmt1.setString(3,min);
psmt1.setString(4,max);
psmt1.setString(5,disc);
psmt1.executeUpdate();
}
catch(Exception ex)
{
out.println("Error in connection : "+ex);
}

以下是我的连接类

package databaseconnection;
import java.sql.*;

public class databasecon
{
    static Connection con;
    public static Connection getconnection()
    {


        try
        {
            Class.forName("com.mysql.jdbc.Driver"); 
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cam","root","root");
        }
        catch(Exception e)
        {
            System.out.println("class error");
        }
        return con;
    }

}

最后错误是

Error in connection : java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'maxvalue,disc) values(AES_ENCRYPT('6', 'key'),AES_ENCRYPT('systolic bp', 'key'),' at line 1

根据我的开发人员的要求,我发布了我的表格结构 Below is my table def:

1 个答案:

答案 0 :(得分:0)

我不知道为什么会这样,但你需要将一个字节数组作为第二个参数传递给MySQL的Damien_The_Unbeliever

AES_ENCRYPT

我说我没有解释,因为AES_ENCRYPT暗示{{1}}的两个参数都是字符串。我自己会犯这个错误。

相关问题