Archive for October 2011

Sign align and release Android application

In order to release your app in the Android market place you need to digitally sign it. The instructions are here. But in short I will show you what you need from the command line, you won’t have to read all the instructions. First off make your app .apk name something different then what your going to use in the end. As the process requires the input and output to have different file names.

Lets take a look, this example is from DOS command line

Create the signature key
C:\Temp> keytool -genkey -v -keystore c:\temp\release-key.keystore -alias MyAlias -keyalg RSA -keysize 2048 -validity 10000

Sign using the key
C:\Temp> jarsigner -verbose -keystore release-key.keystore release.MyApp.apk MyAlias

Verify that it took
C:\Temp> jarsigner -verify -verbose release.MyApp.apk

Run the align tool as recommended
C:\Temp> zipalign -v 4 release.MyApp.apk MyApp.apk

And your all done, now publish it and start watching the downloads.

Java Postgres connection sample

I had to setup Postgres on my linux box, configure and make sure it was working. Since that was the case I started the install, then wrote a very simple Java program to connect and retrieve some data from one of the database tables. The install is simple and pretty easy to google. Once your Postrgres database is up and running you should be able to connect to it. You will need a java Postgres database driver, the one I downloaded was the postgresql-9.1-901.jdbc4.jar then add the jar to your project. And finally to make sure your database is accessible from a program you can use the sample below.

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

// Simple test class to prove connection to Postgres database
public class Main

        public Main()
                { super(); }

        public static void main(String[] args)
                System.out.println(” Postgres Test”);
                Connection myConn = null;
                        // The driver
                        System.out.println(“PostgreSQL JDBC Driver Registered!”);
                        myConn = DriverManager.getConnection( “jdbc:postgresql://”,
                                        “testUser”, “myPassword” );

                        // Connected ?
                        if (myConn != null)
                                System.out.println(“Successfully connected to Postgres Database”);
                        // Get data from the database
                Statement stGetCount = myConn.createStatement();
            ResultSet rs = stGetCount.executeQuery(“SELECT * from  cars”);
            while( )
                System.out.println(“result=” + rs.getString(1) + “,” + rs.getString(2) + “,” + rs.getString(3) );
        catch( Exception ex )
                try{myConn.close();}catch(Exception IDontCare ){}

}  // EOC