Regarding Database

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Regarding Database

Postby shank586 » Mon Jul 21, 2008 11:55 am

Hi all,

I want a tutorial about DataBase, Actually i have seen the tutorials posted by Plusminus but i want in a different way that is database in one activity and my results in another activity could any one please help me out in this i will show u an example the screen shot u will find here is the example my query is if i enter the name and number i should store in the database and i must getback those data in another activity.......
Attachments
Screenshot.PNG
Screenshot.PNG (39.22 KiB) Viewed 425 times
shank586
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 20, 2008 3:22 pm

Top

Postby cgreen » Mon Jul 21, 2008 12:40 pm

What you actually want to do is: Accessing a database from different activities.
This could only be done, if you create and open your database with an absolute path.
afaik this isn't possible, if you're using the google's class SQLiteDatabase.
try to access your database via JDBC ( java.sql.Connection ), then read/write to an absolute path:
e.g: /data/yourdb
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Postby shank586 » Mon Jul 21, 2008 1:04 pm

cgreen wrote:What you actually want to do is: Accessing a database from different activities.
This could only be done, if you create and open your database with an absolute path.
afaik this isn't possible, if you're using the google's class SQLiteDatabase.
try to access your database via JDBC ( java.sql.Connection ), then read/write to an absolute path:
e.g: /data/yourdb


Can u please giveme some example?????
shank586
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 20, 2008 3:22 pm

Postby cgreen » Mon Jul 21, 2008 2:09 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.   public Connection getConnection()
  2.  
  3.   {
  4.  
  5.     if (connection != null)
  6.  
  7.       return connection;
  8.  
  9.     else
  10.  
  11.     {
  12.  
  13.       try
  14.  
  15.       {
  16.  
  17.         Class.forName(ANDROID_SQLITE_DRIVER);
  18.  
  19.         connection = DriverManager.getConnection("/ONDEVICE/SOMEWHERE/DATABASE");
  20.  
  21.       }
  22.  
  23.       catch (ClassNotFoundException e)
  24.  
  25.       {
  26.  
  27.  
  28.  
  29.       }
  30.  
  31.       catch (java.sql.SQLException e)
  32.  
  33.       {
  34.  
  35.  
  36.  
  37.       }
  38.  
  39.     }
  40.  
  41.  
  42.  
  43.     return connection;
  44.  
  45.   }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Postby bavarol » Mon Jul 28, 2008 11:09 am

Hi,

you should know, your Database Context is not so crucial (in an application environment, outside it's another question), i.e. you create a database in Activity1 (you know with sqlitedatabase+Context(also Activity1 in this case), or?) and you want to use this database in Activity2, then you must write a "db = new DBHelper(this);" on the methode onCreate of Activity2 and you can access this database and its tables.
You get this Database, cause DBHelper is so implemented, if a table doesn't exist, it creates it, if so, it opens it!

Please take a look around Contact Application in Internet or Notepad and you'll see what you have to add on Activity2.

Regards
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 5 guests