Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Contributor
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent
Accepted Solution

Insert Image into SQLite as ablob

i have sqlite database and wrok fine and i want to Insert Image into SQLite as ablob but i don't know how to insert and select anybody have any example or link expline this

 

thanks in advansed

Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Insert Image into SQLite as ablob

[ Edited ]
void createSongTablet()
	    {
	    	 try
	         {
	    		 String DB_NAME = "SQLDatal";   
	    		 String dbLocation = "/SDCard/databases/jaw/";             
	             URI uri = URI.create(dbLocation + DB_NAME); 
	             _db = DatabaseFactory.open(uri);
	             Statement st = _db.createStatement( "CREATE TABLE 'songd' ( " +
	                                               "'songId' INTEGER," +
	                                               "'songName' varchar(255), " +
	                                               "'songNameAr' varchar(255), " +
	                                               "'singerId' INTEGER," +
	                                               "'singerName' varchar(255), " +
	                                               "'singerNameAr' varchar(255), " +
	                                               "'albumId' INTEGER," +
	                                               "'albumName' varchar(255), " +
	                                               "'albumNameAr' varchar(255), " +
	                                               "'albumCategory' varchar(255)," +
	                                               "'albumCategoryAr' varchar(255)," +
	                                               "'albumcover' blob,"+
	                                               "'duration' varchar(255), " +
	                                               "'size' varchar(255)," +
	                                               "'byteSize' varchar(255)," +
	                                               "'videoClip' varchar(255)," +
	                                               "'price' varchar(255)," +
	                                               " 'orderDetailId' INTEGER," +
	                                               "'playlistId' INTEGER)" );
	             
	           
	        
	             
	             
	             st.prepare();
	             st.execute();
	             st.close();	             
	             _db.close();
	         }
	         catch (final Exception e ) 
	         {         
	        	
	         }
	    }

 

 void addSongD(int songId, String songName, String songNameAr, int singerId, String singerName, String singerNameAr, 
	             int albumId, String albumName, String albumNameAr, String albumCategory, String albumCategoryAr, 
	             byte[] albumCover, String duration, String trailer, String size, String byteSize, String videoClip, String lyrics, String price, 
	             int orderDetailId,int playListId) throws IllegalArgumentException, MalformedURIException
	    {
	    	 try
		        {
	    		 
		        	String DB_NAME = "SQLDatal";   
		    		String dbLocation = "/SDCard/databases/jaw/";            
		            URI uri = URI.create(dbLocation + DB_NAME); 
		            _db = DatabaseFactory.open(uri);          
		            Statement statement = _db.createStatement("INSERT INTO songd VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); 
		            statement.prepare();                        
		            statement.bind(1, songId); 
		            statement.bind(2, songName); 
		            statement.bind(3, songNameAr); 
		            statement.bind(4, singerId); 
		            statement.bind(5, singerName); 
		            statement.bind(6, singerNameAr); 
		            statement.bind(7, albumId); 
		            statement.bind(8, albumName); 
		            statement.bind(9, albumNameAr); 
		            statement.bind(10, albumCategory); 
		            statement.bind(11, albumCategoryAr);
statement.bind(12, albumCover);
statement.bind(13, duration); //statement.bind(14, trailer); statement.bind(14, size); statement.bind(15, byteSize); statement.bind(16, videoClip); // statement.bind(18, lyrics); statement.bind(17, price); statement.bind(18, orderDetailId); statement.bind(19, playListId); statement.execute(); statement.close(); _db.close(); } catch(final DatabaseException dbe) { } }

 

 

 

 

 

Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Insert Image into SQLite as ablob

Convert the bitmapData to ByteArray and store the byteArray.

 

Read the byteArray and convert to bitmapData.

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Insert Image into SQLite as ablob

I  just copy and paste solution from some other thread. Following is source

 

http://supportforums.blackberry.com/t5/Java-Development/Insert-Image-into-SQLite-as-ablob/m-p/183182...

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Insert Image into SQLite as ablob

on selected u do
final Row row = cursor.getRow();

row.getBlobBytes(11)

it returns byte[]