SlideShare a Scribd company logo
1 of 36
Download to read offline
Developing PGTop for Android
Mark Wong
markwkm@postgresql.org
PostgreSQL Conference West 2010
November 3, 2010
__ __
/ ~~~/  . o O ( Hello! )
,----( oo )
/ __ __/
/| ( |(
^  /___ / |
|__| |__|-"
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 2 / 36
Overview
Slides available at http://www.sideshare.net/markwkm
• What is PGTop for Android?
• Development environment
• Using the PostgreSQL JDBC driver
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 3 / 36
PGTop for Android
A PostgresSQL stats monitoring app
for Android (BSD License):
http://github.com/markwkm/PGTop
Note: Must allow non-Market app to
install because PGTop for Android is
not in the Market.
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 4 / 36
Main Screen
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 5 / 36
Add Database Connection
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 6 / 36
Database Statistics
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 7 / 36
Background Writer Statistics
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 8 / 36
Activity Statistics
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 9 / 36
The Development Environment
A few more details on the following slides about:
• Java (JDK, etc.)
• Android SDK
• Eclipse [optional]
Full system requirement details:
http://developer.android.com/sdk/requirements.html
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 10 / 36
Gentoo Linux Plug
Keep in mind I use a 64-bit Gentoo Linux.
1 The ”g” logo is a trademark of Gentoo Foundation, Inc., and that any Gentoo artwork is
copyright Gentoo Foundation, Inc.
2 The ”g” logo and Gentoo artwork are used in content that pertain to ”the Gentoo project”, as
directed by the Gentoo Foundation, Inc., and not any effort outside or beyond the authority of the
Gentoo Foundation, Inc.
3 The content, project, site, product or any other type of item with which the ”g” logo or Gentoo
artwork is associated is not part of the Gentoo project and is not directed or managed by Gentoo
Foundation, Inc.
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 11 / 36
Java Related Details
• Requires 32-bit Java 5 or 6 development kit (JDK)
http://www.oracle.com/technetwork/java/javase/downloads/
• PostgreSQL JDBC3/4 Driver http://jdbc.postgresql.org version
9.0-801 or later
• Apache Ant http://ant.apache.org/
Additional commentary mostly pertaining to Linux:
• This doesn’t mean it has to be a 32-bit OS
• But if you have a 64-bit OS, both 32- and 64-bit Java is needed, for
building and packaging respectively
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 12 / 36
JDBC3 vs JDBC4
The PostgreSQL JDBC driver is thread-safe. Some additional comments from
http://jdbc.postgresql.org/download.html:
• If you are using the 1.6 JVM, then you should use the JDBC4 version.
• JDK 1.4, 1.5 - JDBC 3. This contains support for SSL and javax.sql, but
does not require J2EE as it has been added to the J2SE release.
• JDK 1.6 - JDBC4. Support for JDBC4 methods is limited. The driver
builds, but the several of the new methods are stubbed out.
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 13 / 36
Android SDK Details
http://developer.android.com/sdk/
• Android emulator
• Android jars
• Android packaging tools
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 14 / 36
Eclipse Details
Optional to have Eclipse Classic 3.4 or 3.5, but must be 32-bit version
http://www.eclipse.org/downloads/
Advantages for using Eclipse:
• GUI designer for building the user interface
• Hides XML
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 15 / 36
Things I learned about
. . . but won’t cover here.
• Using SQLite database methods
• User interface widgets
• Spinner
• TextView
• EditView
• CheckBox
• Toast
• Button
• How the threading model works, or doesn’t work with the user interface
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 16 / 36
Android Programming Examples
• Hello, World (includes example without using Eclipse)
http://developer.android.com/resources/tutorials/hello-world.html
• More examples without using Eclipse
http://developer.android.com/guide/developing/other-ide.html
• More sample applications
http://developer.android.com/resources/samples/
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 17 / 36
PostgreSQL JDBC
Now for some simple examples for connecting to a PostgreSQL database and
querying some data. Warning, code formatted to fit better on these slides. . .
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 18 / 36
Open a Database Connection
Load the PostgreSQL JDBC driver and open a database connection using SSL:
Class.forName("org.postgresql.Driver");
String url;
url = "jdbc:postgresql://pghost:5432/pgdatabase" +
"?sslfactory=org.postgresql.ssl.NonValidatingFactory" +
"&ssl=true";
Connection conn = DriverManager.getConnection(url,
"pguser",
"pgpass");
 Don’t forget to close the connection when you’re done.
 conn.close();
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 19 / 36
Execute a Query
Building on the previous slide, select the name of all relations from pg class
and iterate through every row returned:
String sql;
sql = "SELECT relname FROM pg_class WHERE relkind = ’r’;"
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
 Columns are enumerated starting with 1.
String relname = rs.getString(1);
}
rs.close();
st.close();
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 20 / 36
Execute a Query with a Bind Value
Building on the previous slide, select the number of all relations from pg class:
String sql = "SELECT COUNT(*) FROM pg_class WHERE relkind = ?;"
PreparedStatement ps = conn.createStatement();
// Bind variables are enumerated starting with 1;
ps.setString(1, "r");
ResultSet rs = ps.executeQuery(sql);
rs.next();
long count = rs.getLong(1);
rs.close();
ps.close();
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 21 / 36
More JDBC Code Examples
The PostgreSQL JDBC documentation has more examples at
http://jdbc.postgresql.org/documentation/head/
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 22 / 36
Using cursors
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 23 / 36
Executing INSERT, UPDATE, DELETE SQL statements
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 24 / 36
Creating and modifying database objects
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 25 / 36
Calling stored functions
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 26 / 36
Handling binary data
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 27 / 36
JDBC escapes e.g. strings, outer joins, date-time, scalar functions
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 28 / 36
PostgreSQL Extensions to the JDBC API
• Geometric data types
• Large objects
• Listen/Notify
• Server prepared statements
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 29 / 36
Connection pools
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 30 / 36
Further JDBC Reading
JDBC API Documentation and JDBC Specification
http://jdbc.postgresql.org/documentation/head/reading.html
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 31 / 36
Ready to debug your new app?
After the Android emulator has started the stdout/stderr messages can be
viewed (I didn’t try the debugger).
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 32 / 36
__ __
/ ~~~/  . o O / 
,----( oo ) | Thanks to Google for providing |
/ __ __/ | phones! |
/| ( |(  /
^  /___ / |
|__| |__|-"
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 33 / 36
__ __
/ ~~~/  . o O ( Thank you! )
,----( oo )
/ __ __/
/| ( |(
^  /___ / |
|__| |__|-"
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 34 / 36
Acknowledgements
Hayley Jane Wakenshaw
__ __
/ ~~~/ 
,----( oo )
/ __ __/
/| ( |(
^  /___ / |
|__| |__|-"
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 35 / 36
License
This work is licensed under a Creative Commons Attribution 3.0 Unported
License. To view a copy of this license, (a) visit
http://creativecommons.org/licenses/by/3.0/us/; or, (b) send a
letter to Creative Commons, 171 2nd Street, Suite 300, San Francisco,
California, 94105, USA.
markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 36 / 36

More Related Content

Similar to Developing PGTop for Android

PGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appPGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appMark Wong
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity SecuritySeungmin Shin
 
コミュニティ開発に参加しよう!
コミュニティ開発に参加しよう!コミュニティ開発に参加しよう!
コミュニティ開発に参加しよう!Takahiro Itagaki
 
State of GeoServer
State of GeoServerState of GeoServer
State of GeoServerJody Garnett
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
mago3D workshop(English) in Thailand , 2018.07
mago3D workshop(English) in Thailand , 2018.07mago3D workshop(English) in Thailand , 2018.07
mago3D workshop(English) in Thailand , 2018.07Gaia3D,Inc.
 
GeoServer Developers Workshop
GeoServer Developers WorkshopGeoServer Developers Workshop
GeoServer Developers WorkshopJody Garnett
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsOWASP Kyiv
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCAndroid Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCJim Tochterman
 
Mobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse BindingMobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse BindingTakuya Ueda
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalNAVER D2
 
Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golangSeongJae Park
 
[Droidcon Paris 2013]Multi-Versioning Android Tips
[Droidcon Paris 2013]Multi-Versioning Android Tips[Droidcon Paris 2013]Multi-Versioning Android Tips
[Droidcon Paris 2013]Multi-Versioning Android TipsKenichi Kambara
 

Similar to Developing PGTop for Android (20)

PGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appPGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this app
 
First Bucharest GTUG event 02 Mar 2010
First Bucharest GTUG event 02 Mar 2010First Bucharest GTUG event 02 Mar 2010
First Bucharest GTUG event 02 Mar 2010
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity Security
 
コミュニティ開発に参加しよう!
コミュニティ開発に参加しよう!コミュニティ開発に参加しよう!
コミュニティ開発に参加しよう!
 
State of GeoServer
State of GeoServerState of GeoServer
State of GeoServer
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
mago3D workshop(English) in Thailand , 2018.07
mago3D workshop(English) in Thailand , 2018.07mago3D workshop(English) in Thailand , 2018.07
mago3D workshop(English) in Thailand , 2018.07
 
GeoServer Developers Workshop
GeoServer Developers WorkshopGeoServer Developers Workshop
GeoServer Developers Workshop
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tips
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCAndroid Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
 
Mobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse BindingMobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse Binding
 
Deep dive into serverless on Google Cloud
Deep dive into serverless on Google CloudDeep dive into serverless on Google Cloud
Deep dive into serverless on Google Cloud
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
 
Rock Overview
Rock OverviewRock Overview
Rock Overview
 
Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golang
 
[Droidcon Paris 2013]Multi-Versioning Android Tips
[Droidcon Paris 2013]Multi-Versioning Android Tips[Droidcon Paris 2013]Multi-Versioning Android Tips
[Droidcon Paris 2013]Multi-Versioning Android Tips
 

More from Mark Wong

OHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryOHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryMark Wong
 
OHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportOHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportMark Wong
 
collectd & PostgreSQL
collectd & PostgreSQLcollectd & PostgreSQL
collectd & PostgreSQLMark Wong
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQLMark Wong
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLMark Wong
 
Pg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationPg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationMark Wong
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningPostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningMark Wong
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
Filesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveFilesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...Mark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoPostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...Mark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundPostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...Mark Wong
 
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabpg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabMark Wong
 
Linux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreLinux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreMark Wong
 
pg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLpg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLMark Wong
 
What Is Going On?
What Is Going On?What Is Going On?
What Is Going On?Mark Wong
 

More from Mark Wong (20)

OHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryOHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 Mockumentary
 
OHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportOHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 Report
 
collectd & PostgreSQL
collectd & PostgreSQLcollectd & PostgreSQL
collectd & PostgreSQL
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQL
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
Pg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationPg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentation
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningPostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Filesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveFilesystem Performance from a Database Perspective
Filesystem Performance from a Database Perspective
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoPostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundPostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
 
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabpg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
 
Linux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreLinux Filesystems, RAID, and more
Linux Filesystems, RAID, and more
 
pg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLpg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQL
 
What Is Going On?
What Is Going On?What Is Going On?
What Is Going On?
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Developing PGTop for Android

  • 1. Developing PGTop for Android Mark Wong markwkm@postgresql.org PostgreSQL Conference West 2010 November 3, 2010
  • 2. __ __ / ~~~/ . o O ( Hello! ) ,----( oo ) / __ __/ /| ( |( ^ /___ / | |__| |__|-" markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 2 / 36
  • 3. Overview Slides available at http://www.sideshare.net/markwkm • What is PGTop for Android? • Development environment • Using the PostgreSQL JDBC driver markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 3 / 36
  • 4. PGTop for Android A PostgresSQL stats monitoring app for Android (BSD License): http://github.com/markwkm/PGTop Note: Must allow non-Market app to install because PGTop for Android is not in the Market. markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 4 / 36
  • 5. Main Screen markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 5 / 36
  • 6. Add Database Connection markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 6 / 36
  • 7. Database Statistics markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 7 / 36
  • 8. Background Writer Statistics markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 8 / 36
  • 9. Activity Statistics markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 9 / 36
  • 10. The Development Environment A few more details on the following slides about: • Java (JDK, etc.) • Android SDK • Eclipse [optional] Full system requirement details: http://developer.android.com/sdk/requirements.html markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 10 / 36
  • 11. Gentoo Linux Plug Keep in mind I use a 64-bit Gentoo Linux. 1 The ”g” logo is a trademark of Gentoo Foundation, Inc., and that any Gentoo artwork is copyright Gentoo Foundation, Inc. 2 The ”g” logo and Gentoo artwork are used in content that pertain to ”the Gentoo project”, as directed by the Gentoo Foundation, Inc., and not any effort outside or beyond the authority of the Gentoo Foundation, Inc. 3 The content, project, site, product or any other type of item with which the ”g” logo or Gentoo artwork is associated is not part of the Gentoo project and is not directed or managed by Gentoo Foundation, Inc. markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 11 / 36
  • 12. Java Related Details • Requires 32-bit Java 5 or 6 development kit (JDK) http://www.oracle.com/technetwork/java/javase/downloads/ • PostgreSQL JDBC3/4 Driver http://jdbc.postgresql.org version 9.0-801 or later • Apache Ant http://ant.apache.org/ Additional commentary mostly pertaining to Linux: • This doesn’t mean it has to be a 32-bit OS • But if you have a 64-bit OS, both 32- and 64-bit Java is needed, for building and packaging respectively markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 12 / 36
  • 13. JDBC3 vs JDBC4 The PostgreSQL JDBC driver is thread-safe. Some additional comments from http://jdbc.postgresql.org/download.html: • If you are using the 1.6 JVM, then you should use the JDBC4 version. • JDK 1.4, 1.5 - JDBC 3. This contains support for SSL and javax.sql, but does not require J2EE as it has been added to the J2SE release. • JDK 1.6 - JDBC4. Support for JDBC4 methods is limited. The driver builds, but the several of the new methods are stubbed out. markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 13 / 36
  • 14. Android SDK Details http://developer.android.com/sdk/ • Android emulator • Android jars • Android packaging tools markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 14 / 36
  • 15. Eclipse Details Optional to have Eclipse Classic 3.4 or 3.5, but must be 32-bit version http://www.eclipse.org/downloads/ Advantages for using Eclipse: • GUI designer for building the user interface • Hides XML markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 15 / 36
  • 16. Things I learned about . . . but won’t cover here. • Using SQLite database methods • User interface widgets • Spinner • TextView • EditView • CheckBox • Toast • Button • How the threading model works, or doesn’t work with the user interface markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 16 / 36
  • 17. Android Programming Examples • Hello, World (includes example without using Eclipse) http://developer.android.com/resources/tutorials/hello-world.html • More examples without using Eclipse http://developer.android.com/guide/developing/other-ide.html • More sample applications http://developer.android.com/resources/samples/ markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 17 / 36
  • 18. PostgreSQL JDBC Now for some simple examples for connecting to a PostgreSQL database and querying some data. Warning, code formatted to fit better on these slides. . . markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 18 / 36
  • 19. Open a Database Connection Load the PostgreSQL JDBC driver and open a database connection using SSL: Class.forName("org.postgresql.Driver"); String url; url = "jdbc:postgresql://pghost:5432/pgdatabase" + "?sslfactory=org.postgresql.ssl.NonValidatingFactory" + "&ssl=true"; Connection conn = DriverManager.getConnection(url, "pguser", "pgpass"); Don’t forget to close the connection when you’re done. conn.close(); markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 19 / 36
  • 20. Execute a Query Building on the previous slide, select the name of all relations from pg class and iterate through every row returned: String sql; sql = "SELECT relname FROM pg_class WHERE relkind = ’r’;" Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); while (rs.next()) { Columns are enumerated starting with 1. String relname = rs.getString(1); } rs.close(); st.close(); markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 20 / 36
  • 21. Execute a Query with a Bind Value Building on the previous slide, select the number of all relations from pg class: String sql = "SELECT COUNT(*) FROM pg_class WHERE relkind = ?;" PreparedStatement ps = conn.createStatement(); // Bind variables are enumerated starting with 1; ps.setString(1, "r"); ResultSet rs = ps.executeQuery(sql); rs.next(); long count = rs.getLong(1); rs.close(); ps.close(); markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 21 / 36
  • 22. More JDBC Code Examples The PostgreSQL JDBC documentation has more examples at http://jdbc.postgresql.org/documentation/head/ markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 22 / 36
  • 23. Using cursors markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 23 / 36
  • 24. Executing INSERT, UPDATE, DELETE SQL statements markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 24 / 36
  • 25. Creating and modifying database objects markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 25 / 36
  • 26. Calling stored functions markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 26 / 36
  • 27. Handling binary data markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 27 / 36
  • 28. JDBC escapes e.g. strings, outer joins, date-time, scalar functions markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 28 / 36
  • 29. PostgreSQL Extensions to the JDBC API • Geometric data types • Large objects • Listen/Notify • Server prepared statements markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 29 / 36
  • 30. Connection pools markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 30 / 36
  • 31. Further JDBC Reading JDBC API Documentation and JDBC Specification http://jdbc.postgresql.org/documentation/head/reading.html markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 31 / 36
  • 32. Ready to debug your new app? After the Android emulator has started the stdout/stderr messages can be viewed (I didn’t try the debugger). markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 32 / 36
  • 33. __ __ / ~~~/ . o O / ,----( oo ) | Thanks to Google for providing | / __ __/ | phones! | /| ( |( / ^ /___ / | |__| |__|-" markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 33 / 36
  • 34. __ __ / ~~~/ . o O ( Thank you! ) ,----( oo ) / __ __/ /| ( |( ^ /___ / | |__| |__|-" markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 34 / 36
  • 35. Acknowledgements Hayley Jane Wakenshaw __ __ / ~~~/ ,----( oo ) / __ __/ /| ( |( ^ /___ / | |__| |__|-" markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 35 / 36
  • 36. License This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, (a) visit http://creativecommons.org/licenses/by/3.0/us/; or, (b) send a letter to Creative Commons, 171 2nd Street, Suite 300, San Francisco, California, 94105, USA. markwkm (PGWest 2010) Developing PGTop for Android November 3, 2010 36 / 36