SelimSql

Database Management System

Main Page User Guide Download Java Code Android Contact

Table Of Contents

A. SelimSql Database Admin Application
B. SelimSql Database Driver For Android Developers
C. SelimSql Database Sample Application For Android Developers


A. SelimSql Database Admin Application

This application is a manager of SelimSql database for android:
  • Database/Table Admin Operations
  • Table Edit Record Operations
  • Query Table Operations
  • Export Data Operations



  • B. SelimSql Database Driver For Android Developers

    This driver can be used to manage SelimSql database on local disk and connect to db server for Android applications.

    Android developers can use this library by including "libs" directory of their applications.



    C. SelimSql Database Sample Application For Android Developers

    SSqlDbTest named application source can be used for sample operations.

    SSqlDbTest Application Code Sample:
    package selimsqldb.example;
    
    import java.sql.Connection;
    import java.sql.SQLException;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.Toast;
    
    public class SSqlDbTestActivity extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.mainlayout);
    	}
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.mainlayout, menu);
    		return true;
    	}
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
        	int itemId = item.getItemId();
            if (itemId==R.id.menu_new_database) {
            	doNewDatabase();
            	return true;
            }
            else
            if (itemId==R.id.menu_connect_database) {
            	doConnectDatabase();
            	return true;
            }
            else
            if (itemId==R.id.menu_build_tables) {
            	doBuildTables();
            	return true;
            }
            else
            if (itemId==R.id.menu_insert_update_records) {
            	doInsertUpdateRecords();
            	return true;
            }
            else
            if (itemId==R.id.menu_select_records) {
            	doSelectRecords();
            	return true;
            }
    
            return super.onOptionsItemSelected(item);
        }
    
        private void showToast(String info) {
    		Toast toast = Toast.makeText(this, info, Toast.LENGTH_LONG);
    		toast.show();
        }
    
        public boolean doNewDatabase() {
    		NewSSqlDb newSSqlDb = new NewSSqlDb();
    		Connection connection = null;
    		String error = null;
    		try {
    			connection = newSSqlDb.newDb(DbConstant.SELIMSQL_DB_TEST_NAME);
    			//...
    		}
    		catch(Exception ex) {
    			error = "Error:" + ex.getMessage();
    			System.out.println(error);
    		}
    		finally {
    			newSSqlDb.closeDb(connection);
    		}
    
    		String msg = (error==null ? "NewDbOkay" : error);
    		showToast(msg);
    		return (connection!=null);
        }
    
    
        public boolean doConnectDatabase() {
    		ConnectSSqlDb connectSSqlDb = new ConnectSSqlDb();
    		Connection connection = null;
    		try {
    			connection = connectSSqlDb.connectDb(DbConstant.SELIMSQL_DB_TEST_NAME);
    
    			//...
    		}
    		finally {
    			connectSSqlDb.closeDb(connection);
    		}
    
    		String msg = "ConnectDb:" + (connection==null ? "FAILED" : "SUCCESSFUL");
    		showToast(msg);
    		return (connection!=null);
        }
    
        public boolean doBuildTables() {
    		ConnectSSqlDb connectSSqlDb = new ConnectSSqlDb();
    		Connection connection = null;
    		String error = null;
    		try {
    			connection = connectSSqlDb.connectDb(DbConstant.SELIMSQL_DB_TEST_NAME);
    			if (connection==null)
    				throw new SQLException("Connection Failed!");
    
    			BuildTableSSqlDb buildTableSSqlDb = new BuildTableSSqlDb();
    			buildTableSSqlDb.buildTablesAndIndexes(connection);
    		}
    		catch(Exception ex) {
    			error = "Error:" + ex.getMessage();
    			System.out.println(error);
    		}
    		finally {
    			connectSSqlDb.closeDb(connection);
    		}
    
    		boolean successful = (error==null);
    		String msg = "BuildTables:" + (successful ? "SUCCESSFUL" : error);
    		showToast(msg);
    		return successful;
        }
    
        public boolean doInsertUpdateRecords() {
    		ConnectSSqlDb connectSSqlDb = new ConnectSSqlDb();
    		Connection connection = null;
    		String error = null;
    		try {
    			connection = connectSSqlDb.connectDb(DbConstant.SELIMSQL_DB_TEST_NAME);
    			if (connection==null)
    				throw new SQLException("Connection Failed!");
    
    			DmlOpSSqlDb dmlOpSSqlDb = new DmlOpSSqlDb();
    			dmlOpSSqlDb.insertUpdateDeleteRecords(connection);
    		}
    		catch(Exception ex) {
    			error = "Error:" + ex.getMessage();
    			System.out.println(error);
    		}
    		finally {
    			connectSSqlDb.closeDb(connection);
    		}
    
    		boolean successful = (error==null);
    		String msg = "InsertUpdateRecords:" + (successful ? "SUCCESSFUL" : error);
    		showToast(msg);
    		return successful;
        }
    
        public boolean doSelectRecords() {
    		ConnectSSqlDb connectSSqlDb = new ConnectSSqlDb();
    		Connection connection = null;
    		String error = null;
    		try {
    			connection = connectSSqlDb.connectDb(DbConstant.SELIMSQL_DB_TEST_NAME);
    			if (connection==null)
    				throw new SQLException("Connection Failed!");
    
    			SelectRecSSqlDb selectRecSSqlDb = new SelectRecSSqlDb();
    			selectRecSSqlDb.selectOrderRecords(connection);
    		}
    		catch(Exception ex) {
    			error = "Error:" + ex.getMessage();
    			System.out.println(error);
    		}
    		finally {
    			connectSSqlDb.closeDb(connection);
    		}
    
    		boolean successful = (error==null);
    		String msg = "SelectRecords:" + (successful ? "SUCCESSFUL" : error);
    		showToast(msg);
    		return successful;
        }
    }
    

    C.1. New Database

    Summary Code Sample:
    Class.forName("selimsql.jdbc.DbDriver");
    
    String url = "jdbc:selimsql:fileNewDatabase:MyDb";
    //If you want to build a new database on ssql database server, use this url:
    //Example, jdbc:selimsql://192.168.2.3:9933/fileNewDatabase:MyDb
    
    String user = "admin";
    String pass = null; //No password.
    Connection connection = DriverManager.getConnection(url, user, pass);
    //..
    connection.close();
    

    C.2. Connect to SelimSql Database

    Summary Code Sample:
    Class.forName("selimsql.jdbc.DbDriver");
    
    String url = "jdbc:selimsql:file:MyDb";
    //If you want to connect to a ssql database server, use this url:
    //Example, jdbc:selimsql://192.168.2.3:9933/MyDb
    
    String user = "admin";
    String pass = null; //No password.
    Connection connection = DriverManager.getConnection(url, user, pass);
    //..
    connection.close();
    

    C.3. Build Tables and Indexes

    Summary Code Sample:
    Class.forName("selimsql.jdbc.DbDriver");
    String url = "jdbc:selimsql:file:MyDb";
    String user = "admin";
    String pass = null; //No password.
    Connection connection = DriverManager.getConnection(url, user, pass);
    
    
    Statement statement = connection.createStatement();
    String sql = "CREATE TABLE Product"
    			+ " (ProductId INTEGER NOT NULL,"
    			+ " Name VARCHAR(20) NOT NULL,"
    			+ " Description VARCHAR(50),"
    			+ " Price DECIMAL(15, 2) NOT NULL,"
    			+ " ProductDate DATE NOT NULL,"
    			+ " Status CHAR NOT NULL)";
    
    statement.executeUpdate(sql);
    
    statement.close();
    
    connection.close();
    

    C.4. Insert/Update/Delete Records

    Summary Code Sample:
    Class.forName("selimsql.jdbc.DbDriver");
    String url = "jdbc:selimsql:file:MyDb";
    String user = "admin";
    String pass = null; //No password.
    Connection connection = DriverManager.getConnection(url, user, pass);
    
    
    Statement statement = connection.createStatement();
    String sql = "INSERT INTO Product(ProductId, Name, Description, Price, ProductDate, Status)"
    			+ " VALUES(1, 'Product1', null, 12.35, today(), 'A')";
    statement.executeUpdate(sql);
    
    sql = "update Product"
    	+ " set Description = Name + ' Desc.'"
    	+ " where Description is null";
    statement.executeUpdate(sql);
    
    statement.close();
    
    connection.close();
    

    C.5. Select Records

    Summary Code Sample:
    Class.forName("selimsql.jdbc.DbDriver");
    String url = "jdbc:selimsql:file:MyDb";
    String user = "admin";
    String pass = null; //No password.
    Connection connection = DriverManager.getConnection(url, user, pass);
    
    Statement statement = connection.createStatement();
    String sql = "select * from Order where OrderAmount>=3 and Status='A'";
    ResultSet resultSet = statement.executeQuery(sql);
    int row = 0;
    while(resultSet.next())
    {
    	row++;
    	System.out.print(row + ". OrderId:" + resultSet.getInt("OrderId"));
    	System.out.print(", CustomerId:" + resultSet.getInt("CustomerId"));
    	System.out.print(", ProductId:" + resultSet.getInt("ProductId"));
    	System.out.print(", OrderDate:" + resultSet.getDate("OrderDate"));
    	System.out.print(", OrderAmount:" + resultSet.getShort("OrderAmount"));
    	System.out.print(", UnitPrice:" + resultSet.getDouble("UnitPrice"));
    	System.out.println(", PaymentType:" + resultSet.getString("PaymentType"));
    }
    
    statement.close();
    connection.close();
    

    Copyright © 2009 - 2017 SelimSql