选择包含二进制字段的语句

时间:2018-03-17 19:21:35

标签: mysql binary binary-data

我试图通过识别存储为SMALLINT的userID和存储为BINARY(32)的passwordTest来选择表中的所有数据。这是我用来制作表格的查询:

{   {CREATE TABLE IF NOT EXISTS `test`.`User` 
(`UserID` SMALLINT UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(35) NOT NULL,
`lastname` VARCHAR(35) NOT NULL,
`passwordTest` BINARY(32) NOT NULL,
`registration_date` DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`UserID`),
UNIQUE INDEX `password_UNIQUE` (`passwordTest` ASC));}

以下是我用于将测试值插入表中的查询:

{INSERT INTO USER (firstname, lastname, passwordTest)
VALUES('Test','1','password');}

这是我的SQL查询,它不起作用:

{USE test;
SELECT * FROM USER WHERE userID = '00001' AND passwordTest = 'password';}

非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

因为您将密码列定义为二进制,所以您必须在where子句中将密码转换为二进制。这适用于mysql5.6

try{ File appFolder = new File(Environment.getExternalStorageDirectory() + "/" + Constants.DEFAULT_FOLDER); if (!appFolder.exists()){ appFolder.mkdir(); } File imageFile = new File(Environment.getExternalStorageDirectory() + "/" + Constants.DEFAULT_FOLDER + "/" + mShortName); if (!imageFile.exists()){ URL url = new URL(mImageUrl); Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream()); FileOutputStream out = new FileOutputStream(imageFile); bmp.compress(Bitmap.CompressFormat.PNG, 100, out); } Log.i("error", "" + imageFile.getAbsolutePath()); share(imageFile.getAbsolutePath()); } catch (Exception e){ e.printStackTrace(); mRespHandler.sendEmptyMessage(Constants.RESPONSE_SET_WALLPAPER_ERROR); }