거두절미하고 물어보기 시작하겠습니다 ㅠ.ㅠ...
지금 테이블은
userid, userpass, usernick, userimg 총 네개가 있구요 여기서 userimg만 longblob 형태로 설정되어있고 나머지는 varchar()로
선언되어 있습니다.
궁금한건 update문을 돌리면 userimg에 문법적인 오류가 있다고 나오더군요 ㅠ.ㅠ..
뭐가 잘못된건지.. 전혀 이해가 되질 않네요..ㅠ...
원래 longblob 형태도 아니였고 blob 형태였었는데
혹시 데이터가 너무 많은것 때문이 아닌가 해서 돌려봣는데 그것도 아니구요...
아 그리고 userimg로 넘어오는 데이터는
bitmap -> bytearray - > string 으로 변환해서 최종적으로 넘어오는건 string값입니다..
안드로이드 소스 첨부하고 jsp는 파일로 첨부하겠습니다 ㅠ.ㅠ..
고수님들의 조언좀 부탁드리겠습니다 ㅠ.ㅠ..
package org.member;
//import 문은 삭제하겠습니다.
public class updateMember extends Activity implements OnClickListener {
private ProgressDialog pDialog;
Button updateBtn, reBtn;
EditText etNICK, etPASS;
ImageView userImage;
Button changeImageBtn;
// 선택되서 crop 된 이미지.
Bitmap selectedImage;
byte[] byteArray;
TextView userText;
String userID;
private static final String TEMP_PHOTO_FILE = "temp.jpg"; // 임시 저장파일
private static final int REQ_CODE_PICK_IMAGE = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.adminmember);
userImage = (ImageView) findViewById(R.id.userImage);
changeImageBtn = (Button) findViewById(R.id.changeImageBtn);
changeImageBtn.setOnClickListener(this);
updateBtn = (Button) findViewById(R.id.updateBtn);
updateBtn.setOnClickListener(this);
reBtn = (Button) findViewById(R.id.reBtn);
reBtn.setOnClickListener(this);
etNICK = (EditText) findViewById(R.id.etNICK);
etPASS = (EditText) findViewById(R.id.etPASS);
userID = getIntent().getExtras().getString("id");
userText = (TextView) findViewById(R.id.userText);
userText.setText(userID + "님 환영합니다");
}
private Uri getTempUri() {
return Uri.fromFile(getTempFile());
}
private File getTempFile() {
if (isSDCARDMOUNTED()) {
File f = new File(Environment.getExternalStorageDirectory(), // 외장메모리
// 경로
TEMP_PHOTO_FILE);
try {
f.createNewFile(); // 외장메모리에 temp.jpg 파일 생성
} catch (IOException e) {
}
return f;
} else
return null;
}
/** SD카드가 마운트 되어 있는지 확인 */
private boolean isSDCARDMOUNTED() {
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED))
return true;
return false;
}
/** 다시 액티비티로 복귀하였을때 이미지를 셋팅 */
protected void onActivityResult(int requestCode, int resultCode,
Intent imageData) {
super.onActivityResult(requestCode, resultCode, imageData);
switch (requestCode) {
case REQ_CODE_PICK_IMAGE:
if (resultCode == RESULT_OK) {
if (imageData != null) {
String filePath = Environment.getExternalStorageDirectory()
+ "/temp.jpg";
Log.v("filepath",filePath);
System.out.println("path" + filePath); // logCat으로 경로확인.
selectedImage = BitmapFactory.decodeFile(filePath);
// temp.jpg파일을 Bitmap으로 디코딩한다.
Bitmap resized = Bitmap.createScaledBitmap(selectedImage, 320, 320, true);
byteArray = bitmapToByteArray(resized);
ImageView _image = (ImageView) findViewById(R.id.userImageChange);
_image.setImageBitmap(selectedImage);
// temp.jpg파일을 이미지뷰에 씌운다.
}
}
break;
}
}
@Override
public void onClick(View v) {
if (v == changeImageBtn) {
// 유저 이미지 버튼
Intent intent = new Intent(
Intent.ACTION_GET_CONTENT, // 또는 ACTION_PICK
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*"); // 모든 이미지
intent.putExtra("crop", "true"); // Crop기능 활성화
intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri()); // 임시파일 생성
intent.putExtra("outputFormat", // 포맷방식
Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(intent, REQ_CODE_PICK_IMAGE);
// REQ_CODE_PICK_IMAGE == requestCode
}else if(v==updateBtn){
updateProcess();
}
else if (v == reBtn) {
// 다시 쓰기 버튼.
etNICK.setText("");
etPASS.setText("");
}
}
// 비트맵 -> ByteArray
public byte[] bitmapToByteArray(Bitmap $bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
$bitmap.compress(CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
// ByteArray -> 비트맵.
public Bitmap byteArrayToBitmap(byte[] $byteArray) {
Bitmap bitmap = BitmapFactory.decodeByteArray($byteArray, 0,
$byteArray.length);
return bitmap;
}
public String parsingData(InputStream input) {
String result = null;
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(new InputStreamReader(input));
while (parser.next() != XmlPullParser.END_DOCUMENT) {
String name = parser.getName();
if (name != null && name.equals("result"))
result = parser.nextText();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public void ContentViewCall() {
Intent intent = new Intent(this, contentView.class);
intent.putExtra("id", etNICK.getText().toString());
startActivity(intent);
finish();
}
private final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pDialog.dismiss();
String result = msg.getData().getString("RESULT");
if (result.equals("success")) {
Toast.makeText(updateMember.this, "성공적으로 회원정보를 수정 하였습니다.",
Toast.LENGTH_LONG).show();
ContentViewCall();
} else {
Toast.makeText(updateMember.this, "회원수정 실패", Toast.LENGTH_LONG)
.show();
}
}
};
public void updateProcess() {
final ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
@Override
public String handleResponse(HttpResponse response)
throws ClientProtocolException, IOException {
String result = null;
HttpEntity entity = response.getEntity();
result = parsingData(entity.getContent());
Message message = handler.obtainMessage();
Bundle bundle = new Bundle();
if (result.equals("success")) {
bundle.putString("RESULT", "success");
Log.v("regedit", "regedit ok !" + result);
} else {
bundle.putString("RESULT", "failed");
Log.v("regedit", "regedit no !" + result);
}
message.setData(bundle);
handler.sendMessage(message);
return result;
}
};
// 로그인이 처리되고 있다는 다이얼로그를 화면에 표시한다.
pDialog = ProgressDialog.show(this, "", "회원정보수정 처리중");
// 서버에 HTTP 처리 요청은 새로운 스레드를 생성하여 비동기식으로 처리하는것이 효율적이다.
new Thread() {
@Override
public void run() {
String url = "http://192.168.0.3:8080/jws/mixare/member/update.jsp";
HttpClient http = new DefaultHttpClient();
try {
// 서버에 전달할 파라메터 세팅
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", userID));
Log.v("id", userID);
if (etNICK.getText().toString().equals("")) {
nameValuePairs.add(new BasicNameValuePair("nick", ""));
Log.v("passwd", etNICK.getText().toString());
} else {
nameValuePairs.add(new BasicNameValuePair("nick",
etNICK.getText().toString()));
Log.v("passwd", etNICK.getText().toString());
}
if (etPASS.getText().toString().equals("")) {
nameValuePairs.add(new BasicNameValuePair("nick", ""));
Log.v("passwd", etPASS.getText().toString());
} else {
nameValuePairs.add(new BasicNameValuePair("nick",
etPASS.getText().toString()));
Log.v("passwd", etPASS.getText().toString());
}
nameValuePairs.add(new BasicNameValuePair("img",
new String(byteArray)));
Log.v("image ?", new String(byteArray));
// 응답시간이 5초가 넘으면 timeout 처리하려면 아래 코드의 커맨트를 풀고 실행한다.
HttpParams params = http.getParams();
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 5000);
// HTTP를 통해 서버에 요청을 전달한다.
// 요청에 대한결과는 responseHandler의 handleResponse()메서드가 호출되어
// 처리한다.
// 서버에 전달되는 파라메터값을 인코딩하기위해 UrlEncodedFormEntity() 메서드를 사용한다.
HttpPost httpPost = new HttpPost(url);
UrlEncodedFormEntity entityRequest = new UrlEncodedFormEntity(
nameValuePairs, "UTF-8");
httpPost.setEntity(entityRequest);
http.execute(httpPost, responseHandler);
Log.v("to jsp", "to jsp is success");
} catch (Exception e) {
e.printStackTrace();
}
}
}.start(); // 스레드를 실행시킨다.
}
}