Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
package handler;

import java.util.ArrayList;

import property.property;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Property;

public class handler extends SQLiteOpenHelper
{

	static String Database_Name="rajkot_tourism.db";
	String Table_Name1="cat_tbl";
	String Cat_ID="cat_id";
	String Cat_Name="cat_name";
	String Area_ID="area_id";
	String Area_Name="erea_name";
	String Table_Name2="area_tbl";
	String Table_Name3="place_tbl";
	int idc;
	int ida;
	
	
	public handler(Context context) 
	{
		super(context,Database_Name,null,1);
		
	}

	@Override
	public void onCreate(SQLiteDatabase db) 
	{
	
		db.execSQL("CREATE TABLE cat_tbl(cat_id INTEGER PRIMARY KEY AUTOINCREMENT,cat_name TEXT)");
		db.execSQL("INSERT INTO cat_tbl(cat_name)VALUES('Attraction'),('Hotels'),('Restaurants'),('Shopping'),('Temples')");
		db.execSQL("CREATE TABLE area_tbl(area_id INTEGER PRIMARY KEY AUTOINCREMENT,area_name TEXT)");
		db.execSQL("INSERT INTO area_tbl(area_name)VALUES('Near Bus Stand'),('Yagnik Road'),('Limada Chowk'),('Kalawad Road'),('University Road'),('150 Ring Road'),('Other')");
		db.execSQL("CREATE TABLE place_tbl(place_id INTEGER PRIMARY KEY AUTOINCREMENT,place_name TEXT,place_address TEXT,place_image TEXT,place_desc TEXT,place_phno INTEGER,place_web TEXT,cat_id INTEGER REFERENCES cat_tbl(cat_id),area_id INTEGER REFERENCES area_tbl(area_id),place_latitude double,place_longitude double)");
		
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('Confort INN Legacy','Panchnath Rd, Rajkot, Gujarat 360001','@drawable/confort_legacy','Comfort inn Legacy create hotel products that offer the highest standards and sense of value for money to our guests. Moreover, we have been providing the highest standard of customer satisfaction from all the brand segments of the hotel industry.Hotel Comfort INN Legacy,Rajkot continues to excels through innovative hospitality solutions.It has pioneered unique food and beverage concepts. AMBROSIA Multicuisine restaurant unanimously hailed as some of the finest Restaurant in the country.','0281 301 8555','http://hotelcomfortinnlegacy.com/','2','3','22.296055','70.798691')");
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('The Imperial Palace','Dr. Yagnik Road, Rajkot, India','@drawable/imperial_palace','The Imperial Palace hotel Rajkot is a masterpiece of simplicity,comfort and elegance, offering the ultimate in luxury,with the most spacious rooms among Rajkot hotels. Each one of the hotels opulent guest rooms is comfortable and stylish and equipped with advanced technology for the convenience of hotel guests - underlined, of course, by the extremely professional and sincere service by the Imperial staff which makes it stand out from other Rajkot hotels','0281 2480000','http://www.theimperialpalace.biz/','2','2','22.29523','70.7908')");
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('Silver Palace','Yagnik Road Corner, Near Malaviya Petrol Pump, Rajkot','@drawable/silver_palace','Hotel Silver Palace, among the premier business hotels in Rajkot,the economic capital of Saurashtra is characterised by the traditional Kathiawari hospitality. Located in the heart of the city, in the vicinity of the exclusive mercantile & residential area of Rajkot.Silver Palace provides easy access to the airport and railway station which are just 3 kms away.Modern facilities with the finest hospitality makes it the ideal choice amongst hotels in Rajkot for businessmen and tourist.','0281 2480008','www.hotelsilverpalace.com','2','1','22.3038945','70.80215989')");
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('Khirasara Palace','Kalawad Road, Nr. Metoda G.I.D.C., At : Khirsara (Ranmalji), Rajkot (Gujarat) India','@drawable/khirasara_palace','Situated 14 kms away from the bustling city of Rajkot, on Kalawad road-experience serenity, peace & clean fresh breeze, whilst being surrounded by the rich heritage, history & royal comfort within this grand monumental property spread over 7 acres.The majestic monument of Khirasara, which has witnessed the rich heritage and culture of the glorious past of Kathiawar,and has borne the brunt of centuries of history,now stands in its fullest splendour and glory, in the resplendent present.','02827 288444','http://www.khirasarapalace.in','2','4','22.2391534',' 70.65271129999')");
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('Pradhyuman Lords Inn','Everest park, near Love Mandir Kalawad Road, Rajkot - 360005','@drawable/pradhyuman_lords','Pradhyuman Lords Inn is a contemporary designed business hotel situated at Kalawad Road.The hotel is ideally located at few minutes drive from the Rajkot railway station & the Airport.The hotel is created keeping in mind utmost guest comfort having 68 well furnished rooms.With latest amenities like Mini Bar, Snack basket in all Rooms & 24hrs Room Service,Wi-Fi Connectivity, Direct Dialing Facility, Electronic Vault & LCD TV, In house Laundry & Valet Service,Doctor on Call, Travel Desk, Business Center','0281 2562880','www.lordshotels.com','2','4','22.2726111','70.7581584')");
	}
	
	public ArrayList<property> display_cat()
	{
		ArrayList<property> ar=new ArrayList<property>();
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query("cat_tbl", null, null, null, null, null, null);
		
		property p;
		while(c.moveToNext())
		{
			p=new property();
			p.setCat_id(c.getInt(0));
			p.setCat_name(c.getString(1));
			ar.add(p);
		}
		sd.close();
		return ar;
		
	}
	
	public void image()
	{

	}
	public ArrayList<property> display_area()
	{
		ArrayList<property> ar=new ArrayList<property>();
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query("area_tbl", null, null, null, null, null, null);
		
		property p;
		while(c.moveToNext())
		{
			p=new property();
			p.setArea_id(c.getInt(0));
			p.setArea_name(c.getString(1));
			ar.add(p);
		}
		sd.close();
		return ar;
		
	}
	
	public property searchbyid(int id)
	{
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query(Table_Name1, null, Cat_ID+"="+id, null, null, null, null);
		
		
		property p=new property();
		
		while(c.moveToNext())
		{
			p.setCat_name(c.getString(1));
		}
		return p;
		
	}
	
	public property searchbyidarea(int id)
	{
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query(Table_Name2, null, Area_ID+ "="+ id, null, null, null, null);
		property p=new property();
		
		while(c.moveToNext())
		{
			p.setArea_name(c.getString(1));
		}
		return p;
		
	}
	public ArrayList<property> showplaceid(int idc,int ida)
	{
		SQLiteDatabase sd=getReadableDatabase();
		//String query=("select * from place_tbl where Cat_ID=idc AND Area_ID =ida");
		//Cursor c=sd.rawQuery(query, null);
		Cursor c=sd.query(Table_Name3,null,Cat_ID+"="+idc+" AND " +Area_ID+"="+ida,null,null,null, null);
		
		ArrayList<property> ar=new ArrayList<property>();
		property p;
		while(c.moveToNext())
		{
			p=new property();
			p.setPlace_name(c.getString(1));
			ar.add(p);
		}
		sd.close();
		return ar;
		
	}
	
	public ArrayList<property> display_place()
	{
		ArrayList<property> ar=new ArrayList<property>();
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query(Table_Name3, null, null, null, null, null, null);
		
		property p;
		while(c.moveToNext())
		{
			p=new property();
			p.setPlace_address(c.getString(0));
			p.setPlace_id(c.getInt(1));
			p.setPlace_name(c.getString(2));
			p.setPlace_image(c.getString(3));
			p.setPlace_desc(c.getString(4));
			p.setPlace_phno(c.getInt(5));
			p.setPlace_web(c.getString(5));
			p.setPlace_latitude(c.getDouble(6));
			p.setPlace_longitude(c.getDouble(7));
			ar.add(p);
		}
		sd.close();
		return ar;
	}
	

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		// TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + Table_Name1);
        db.execSQL("DROP TABLE IF EXISTS " + Table_Name2);
        db.execSQL("DROP TABLE IF EXISTS " + Table_Name3);



	}

}
Posted

1 solution

There are two ways to handle this situation:

1. Not to save the image in the DB at all. Instead save the image somewhere on the persistent memory like SDCard in hidden folder. And access the image.

2. Save the image as byte array in the DB. And create the image after reading the byte array data from DB and show it on the screen.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900