Peguei isto de um Livro mas não tenho ideia de como usar :
[code]import android.R;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBHelper extends SQLiteOpenHelper {
private static final String DBPath = "";
private static final String DBName = "metric_mobile_db";
private static final int DBVersion = 1;
private final Context mContext;
public DBHelper(Context context){
super(context, DBName, null, DBVersion);
this.mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String[] sql = mContext.getString(0x7f040002).split("\n");
db.beginTransaction();
try {
execMultipleSQL(db, sql);
db.setTransactionSuccessful();
} catch (SQLException e) {
// TODO: handle exception
Log.e("Erro ao Criar Tabelas e Dados de Depuração", e.toString());
throw e;
}
finally{
db.endTransaction();
}
}
private void execMultipleSQL(SQLiteDatabase db, String[] sql) {
for(String s : sql){
if(s.trim().length() > 0)
db.execSQL(s);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
String[] sql = mContext.getString(0x7f040003).split("\n");
db.beginTransaction();
try {
execMultipleSQL(db, sql);
db.setTransactionSuccessful();
} catch (SQLException e) {
// TODO: handle exception
Log.e("Erro ao Criar Tabelas e Dados de Depuração", e.toString());
throw e;
}
finally{
db.endTransaction();
}
onCreate(db);
}
}[/code]
Este código posta em um servidor rodando uma aplicação em php que não é o meu caso :
public class WebAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText text = (EditText)findViewById(R.id.texto_tela);
final Button button = (Button)findViewById(R.id.button);
final TextView content = (TextView)findViewById(R.id.content);
button.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
String texto = text.getText().toString();
texto = texto.replace(" ","%20");
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://10.1.1.2/flpnm/jaydson/android/?texto=" + texto);
try{
client.execute(request);
content.setText("A mensagem: '" +text.getText().toString() + "' foi inserida com sucesso...");
}catch(Exception ex){
content.setText("Falhou");
}
}
});
}
}
[code]
if($_GET){
$link = mysql_connect('localhost','root','1234');
$db_selected = mysql_select_db('test', $link);
$query = "INSERT INTO tabela (texto) VALUES ('".$_GET['texto']."')";
$result = mysql_query($query);
}[/code]
Alguém tem ideia como faço isso no próprio banco do Celular ?
