Skip to content

Instantly share code, notes, and snippets.

View msdalp's full-sized avatar

Mustafa Alparslan msdalp

View GitHub Profile
package com.msd.jetty;
public class App {
public static void main(String[] args) {
final Jetty jetty = new Jetty(8080);
jetty.start();
Thread.sleep(500);
if (false == jetty.isStarted()) {
throw new Exception("Cannot start jetty server");
package com.msd.jetty;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
package com.msd.jetty;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
package com.msd.jetty;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
public class Jetty extends Server {
package com.test.db;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.util.List;
import com.test.db.MainActivity.Data;
package com.test.db;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import java.util.LinkedList;
import java.util.List;
public class MainActivity extends Activity {
public class MyDb extends SQLiteOpenHelper {
public static final String TAG = "MyDb";
public static final int VERSION = 1;
public static final String DATABASENAME = "mydb";
public MyDb(Context context) {
super(context, DATABASENAME, null, VERSION);
}
@Override
Cursor cursor = getReadableDatabase().
rawQuery("select * from data where ID = ?", new String[] { _id });
database.query("data",
new String[] { ID, DATA_ID, VALUE },
null, null, null, null, null);
public synchronized String getDataValue(long _id) {
final SQLiteDatabase db = this.getReadableDatabase();
String retval = null;
try {
Cursor cursor = db.query("data", new String[]{"VALUE"},
"ID = ?", new String[]{String.valueOf(_id)}, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
retval = cursor.getString(0);
public synchronized boolean addData(List<YourObject> _objects) {
final SQLiteDatabase db = this.getWritableDatabase();
boolean retval = false;
try {
for (YourObject object : _objects) {
ContentValues contentValues = new ContentValues();
contentValues.put("ID", object.id);
contentValues.put("DATA_ID", object.dataId);
contentValues.put("VALUE", object.value);
db.insert("data",null,contentValues);