-- 제가 지금 안드로이드에서 post방식으로 MYSQL, PHP 로 되어있는 웹서버로 값 받아 올려는데요..
밑에 있는게 제가 했는 소스들입니다.
제대로 안되는거 같은데 .. 버튼을 눌렀는데 소식이 없습니다.. 머가 잘못되었는지 ㅜㅜ...
< 안드로이드 >
package com.sungwoo.room;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Room_information extends Activity {
TextView TextResult;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextResult = (TextView)findViewById(R.id.text_result);
Button btnOk = (Button)findViewById(R.id.btnOK);
btnOk.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
HttpPostData();
}
});
}
//------------------------------
// Http Post
//------------------------------
public void HttpPostData() {
try {
//--------------------------
// URL
//--------------------------
URL url = new URL("http://localhost/index.php);
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setDefaultUseCaches(false);
http.setDoInput(true);
http.setDoOutput(true);
http.setRequestMethod("POST");
http.setRequestProperty("content-type", "application/x-www-form-urlencoded");
InputStreamReader tmp = new InputStreamReader(http.getInputStream(), "EUC-KR");
BufferedReader reader = new BufferedReader(tmp);
StringBuilder builder = new StringBuilder();
String str;
while ((str = reader.readLine()) != null) {
builder.append(str + "\n");
}
TextResult.setText(builder.toString());
} catch (MalformedURLException e) {
// err msg
} catch (IOException e) {
// err msg
} // try
} // HttpPostData
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button android:layout_width="wrap_content" android:text="Button" android:id="@+id/btnOK" android:layout_height="wrap_content"></Button>
<TextView android:id="@+id/text_result" android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content"></TextView>
</LinearLayout>
// MYSQL FIELD NAME
// LT_Code -- 과목코드
// LT_Name -- 과목명
// LT_Professor -- 교수님
// LT_St_Time -- 수업시작시간
// LT_Ed_Time -- 수업마침시간
// LT_Day -- 요일
// CL_Name -- 강의실명
<html>
<body>
<table border=1>
<?php
// php와 mysql 연결
$connect = mysql_connect("localhost", "root", "1234")
or die("MySQL에 연결할수 없습니다.");
// database 선택
if(!mysql_select_db("android1079", $connect))
die("데이터베이스를 선택할수 없습니다.");
mysql_query("set names euckr");
$sql = "select * from d127";
if(!mysql_query($sql, $connect)) die("연결이 안됩니다.");
mysql_query($sql, $connect);
$result = mysql_query($sql, $connect);
// column 수
$fields = mysql_num_fields($result);
// 화면에 출력.
echo "<tr> <td colspan=7 > 디지털관 입니다. </td></tr>";
echo "<tr>
<td> 과목코드 </td>
<td> 과목명 </td>
<td> 교수님 </td>
<td> 수업시작시간 </td>
<td> 수업마침시간 </td>
<td> 요일 </td>
<td> 강의실 </td> </tr>" ;
while($row = mysql_fetch_assoc($result)) {
echo "<tr>
<td>" . $row["LT_Code"] . "</td>";
echo "<td>" . $row["LT_Name"] . "</td>";
echo "<td>" . $row["LT_Professor"] . "</td>";
echo "<td>" . $row["LT_St_Time"] . "</td>";
if($row["LT_Ed_Time"] == null){
echo "<td>" . $row["LT_St_Time"] . "</td>";
echo "<td>" . $row["LT_Day"] . "</td>";
} else {
echo "<td>" . $row["LT_Ed_Time"] . "</td>";
echo "<td>" . $row["LT_Day"] . "</td>";
}
echo "<td>" . $row["CL_Name"] . "</td> </tr>";
}
mysql_close($connect);
?>
</table>
</body>
</html>




뭐 어디서 문제가 있는지도 모르겠고, 어떤 문제가 있는지도 도저히 감을 못잡겠네요;
이런식으로 올리시면 아무도 도움을 드릴 수 없을 겁니다.