Saturday 14 June 2014

How to know IMEI number of your Andorid device?

Background

The International Mobile Station Equipment Identity or IMEI is a number, usually unique, to identify 3GPP (i.e., GSM, UMTS and LTE) and iDEN mobile phones, as well as some satellite phones. It is used to block a device from the network in case the phone is stolen. The IMEI is only used for identifying the device and has no permanent or semi-permanent relation to the subscriber. Lets see different ways to view this IMEI number for your android device.

  1. Easiest and simplest way is to dial *#06# from your phone and IMEI number will be displayed on your phone.


    Note : Mine is a dual sim android phone. Hence getting 2 IMEI numbers. Also remember IMEI has nothing to do with network or sim you are using. Instead, the subscriber is identified by transmission of an IMSI number, which is stored on a SIM card that can (in theory) be transferred to any handset.It is just to identify your device over network and if you have to slots for sim card then you will be having two IMEI numbers.
  2. View it in the setting of phone.

    1. Go to System Settings -> About Phone -> Status
    2. Here you should see a row name IMEI information .
    3. In that you will find your IMEI number.



  3. Another way to find IMEI number is to log into the google account which is used to log into google services like playstore on your device. 

    1. Go to https://www.google.com/settings/dashboard.
    2. Select the Android section (4th from top).
    3. You should see your android IMEI number listed there.


  4. Lastly you can always get to know your IMEI number as it will be mentioned on the back of your device. Open the device remove the battery and you should see your IMEI number mentioned there. I have picked up a random picture displaying this.

On Losing the Phone

When you lose your handset, you will need to launch a FIR with the police, attaching a copy of the IMEI number with it. Then give a copy of this to your service provider who can track the phone based on its unique ID number and meanwhile block the handset so that it cannot be used by anyone else. IMEI number helps to tracks the handset, even when the SIM is changed or the SIM card is not activated. Once the phone is traced, the police should be able to retrieve it. 

Important Points to Note

  • Android does not support multiple SIMs, at least from the SDK. Device manufacturers who have created multi-SIM devices are doing so on their own. So programmatically it is difficult to retrieve two IMEI numbers for a dual sim phone.
  • IMEI value survives device wipes (“Factory resets”).
  • IMEI number is device specific. It does not depend on what network provider you are using.

 

Important Links 

Connect to a database in Java

Goal

In my last post I showed how to change the default password of mysql in wamp. In this post I will show how can we connect to a database(mysql is this case) using Java. You must have mysql database installed for this.

Setup

Prior to start coding lets see what we need to complete this goal. We have mysql installed.

  1. Create a database called testDB . We will connect to this DB.
  2. Use that DB.
  3. Create a table name employee with columns as name, sex and age.
  4. Use describe command to verify the table details.
  5. Use slelect query on this newly formed table. No data is displayed.
  6. Add two enteries.
  7. Use select query again to verify data is added.




Getting Started

Lets start with writing code now. 

  1. Create a project name DBDemo.
  2. In that create a java class file named DBConnectionDemo.

In that write the following source code.

package com.opensourceforgeeks;

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

public class DBConnectionDemo {
    
    public final static String query = "select * from employee";
    
    
    public static void main(String args[]) {
        
        String connectionURL = "jdbc:mysql://localhost:3306/testDB";
        Connection connection = null;
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            System.out.println("Driver not found. Provide the driver jar in the class path.");
            e.printStackTrace();
        }
        try {
            connection = DriverManager.getConnection(connectionURL, "root", "thakur");
            Statement stmnt = connection.createStatement();
            ResultSet resultSet = stmnt.executeQuery(query);
            while(resultSet.next()){
                System.out.println("Name : " + resultSet.getString(1) + " Sex : " + resultSet.getString(2) + " Age : " + resultSet.getInt(3));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        
    }
}



Expected output at this point :

Driver not found. Provide the driver jar in the class path.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.opensourceforgeeks.DBConnectionDemo.main(DBConnectionDemo.java:19)
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/testDB
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.opensourceforgeeks.DBConnectionDemo.main(DBConnectionDemo.java:25)



This is expected as we have not added the required driver jar file yet. So add the jar to your classpath.

  1. Right click the project and selectproperties.
  2. Go to java build path -> libraries
  3. Select add external library and add the mysql connector jar(download)



Now rerun the program. You should get the correct output.


Name : Aniket Sex : Male Age : 23
Name : Abhijit Sex : Male Age : 21



NOTE :  If you are using java 7 like me the there is no need to even load you driver class using Class.forName() because java7 comes with JDBC 4 and for JDBC 4 appropriate driver class will automatically be picked up from the class path. So all you have to do is add the jar in the class path.


Related Links

Changing default mysql password in WAMP server.

Background

WAMP is "Windows, Apache, MySQL, and PHP", an application server platform.
You can download it from WAMP site.
 Default password for mysql is String with no length. So on getting prompt for password simply pressing enter would log you into the mysql console as root.

Understanding the architecture

Lets understand where this password for root use is stored. We can then see how can we go modifying it. To start with open mysql console. It will ask for password simply press enter. You should see the following screen.


Next take a look at the databases that come preconfigured. For that simply execute 

mysql > show databases;

You should get some databases. The database we are interested in is mysql database. So go ahead and and execute

mysql > use mysql;

You should get message database changed. See following screen shot


If you wish to see tables in this database you can do

mysql > show tables;

You will see all the tables in this mysql database. The table we are interested in is the table user.



If you want to see what columns make up this table user and what is its data type you can execute following command.

mysql > describe user;

  You can see a lot of columns in the table. But columns that are of our interest are Host, User and Password. Host is the URL. Like you can have localhost or 127.0.0.1 etc. User is the user for which the row is. Example can be the root (This is the user for which we will be changing the password). But you can also have other users and add new users. Finally password is the password that the particular user enter when he logs into mysql console.


Now we know that the default password is a String with no length i.e "". Lets verify this
 Run following command - 

 mysql > select host,user,password from user where user='root';

This should show you that the password is a blank value.

Changing the password

With the above background lets change our password. Execute the following command

mysql > update user set password=PASSWORD('newpassword') where user='root';

(Replace newpassword with your password) .

Note : Password will be stored as encrypted String.

Then you can verify that the tables are indeed changes using previous query

 mysql > select host,user,password from user where user='root';


 Now you will have to flush privileges.

mysql > flush privileges;


You have changed your password successfully. Next time you login to mysql console you will have to enter this password. To exit mysql console simple use exit command.

mysql > exit


Related Links

t> UA-39527780-1 back to top