package com.asd;
import android.app.*;
import android.content.*;
import android.database.*;
import android.database.sqlite.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import com.asd.*;
public class asd extends Activity {
WordDBHelper mHelper;
EditText mText;EditText mText1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mHelper = new WordDBHelper(this);
mText = (EditText)findViewById(R.id.edittext);
mText1 = (EditText)findViewById(R.id.edittext1);
findViewById(R.id.insert).setOnClickListener(mClickListener);
findViewById(R.id.delete).setOnClickListener(mClickListener);
findViewById(R.id.update).setOnClickListener(mClickListener);
findViewById(R.id.select).setOnClickListener(mClickListener);
}
Button.OnClickListener mClickListener = new View.OnClickListener() {
public void onClick(View v) {
SQLiteDatabase db;
ContentValues row;
String Edit_text=mText.getText().toString();
String Edit_text1=mText1.getText().toString();
switch (v.getId()) {
case R.id.insert:
db = mHelper.getWritableDatabase();
// insert ����� ����
if(mText.length()!=0 && mText1.length()!=0 )
{
Edit_text=mText.getText().toString();
Edit_text1=mText1.getText().toString();
mText.setText("");
mText1.setText("");
row = new ContentValues();
row.put("eng", Edit_text);
row.put("han", Edit_text1);
db.insert("dic", null, row);
}
// SQL ������� ����
mHelper.close();
mText.setText("Insert Success");
break;
case R.id.delete:
db = mHelper.getWritableDatabase();
// delete ����� ����
db.execSQL("DELETE FROM dic;");
mHelper.close();
mText.setText("Delete Success");
break;
case R.id.update:
db = mHelper.getWritableDatabase();
// update ����� ����
Edit_text=mText1.getText().toString();
row = new ContentValues();
row.put("han", Edit_text1);
Edit_text1=mText1.getText().toString();
//String Ed=mText1.getText().charAt(0);
row = new ContentValues();
row.put("han", Edit_text1);
db.update("dic", row, Edit_text, null );
//db.execSQL("UPDATE dic SET han = 'Ed' WHERE eng = 'a';");
mHelper.close();
mText.setText("Update Success");
mText1.setText("");
break;
case R.id.select:
db = mHelper.getReadableDatabase();
Cursor cursor;
// query ����� �б�
//cursor = db.query("dic", new String[] {"egg", "han"}, null,
// null, null, null, null);
// SQL ������� �б�
cursor = db.rawQuery("SELECT eng, han FROM dic", null);
String Result = "";
while (cursor.moveToNext()) {
String eng = cursor.getString(0);
String han = cursor.getString(1);
Result += (eng + " = " + han + "\n");
}
if (Result.length() == 0) {
mText.setText("Empyt Set");
} else {
mText.setText(Result);
}
cursor.close();
mHelper.close();
break;
}
}
};
}
class WordDBHelper extends SQLiteOpenHelper {
public WordDBHelper(Context context) {
super(context, "EngWord.db", null, 1);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE dic ( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"eng TEXT, han TEXT);");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS dic");
onCreate(db);
}
}
-------------------이건 DB<소스>구요---------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/insert"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Insert"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/insert"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Insert"
/>
<Button
android:id="@+id/delete"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
/>
<Button
android:id="@+id/update"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
/>
<Button
android:id="@+id/select"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/edittext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
--------------------이건 DB<레이이아>입니다-----------------
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class ss implements Runnable {
public static final String serverIP = "192.168.126.1";
public static final int serverPort = 7582;
@Override
public void run() {
// TODO Auto-generated method stub
try {
System.out.println("S: Connecting...");
ServerSocket serverSocket = new ServerSocket(serverPort);
while (true) {
Socket client = serverSocket.accept();
System.out.println("S: Receiving...");
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(client.getInputStream()));
String str = in.readLine();
System.out.println("S: Received: '" + str + "'");
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(client.getOutputStream())),
true);
out.println("Server Received " + str);
} catch (Exception e) {
System.out.println("S: Error");
e.printStackTrace();
} finally {
client.close();
System.out.println("S: Done.");
}
}
} catch (Exception e) {
System.out.println("S: Error");
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread desktopServerThread = new Thread(new ss());
desktopServerThread.start();
}
}
----------------이건 서버 소스입니다------------------
근데 DB는 안드로이드로 만들었고, 서버는 자바로 만들었는데, 혹시 같이 사용할수 있는건가요???