Java database manipulation with singleton

Alright, today we are going to have some database manipulation in JAVA. This will be done by using a Singleton – class for our database connections, Data Access Objects for our SQL – commands and Value Objects to get and set our data.
Read more

c++ part1 – 2 dimensional array filled with rand()

In this first c++ tutorial we are going to fill a 2 dimensional array and search for a specific alphabetic character.

I’m going to give you the code first, because there isn’t much explaining to do here.

#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int main(){
        srand(time(0));
	const int ROW=5,COL=4;
	char table [ROW][COL] ;

	for(int r=0; r < ROW ;r++){
		for (int k=0; k < COL; k++){
			table[r][k] = rand()%26 + 'a';
			cout << table[r][k] << "\t";
		}
		cout << endl;
	}

	for (int i=0; i<5; i++){
		for (int j=0; j<4; j++){
			if (table[i][j] == 'a')
			cout <<"a appears on row "<<i+1<<" column "<<j+1<<endl;
		}
	}
	return 0;
}

As you can see I first declared the numbers of rows and columns, needed for the array and made them constant, so it won’t be possible to alter the variable afterwards.

Then after I created the array, I start writing random numbers in it with “rand()%26 + ‘a’;”
%26 will ensure that the numbers that are being generated will lay between 0 and 26, the “+ ‘a’” will be added somewhere in the array.

To be sure that every time a new random number is chosen you will need to use the function “srand(time(0));”

As some of you may notice, the numbers will be transformed into alphabetic characters, because the array is declared as char and every number that is generated stands for an alphabetic character.

Got questions, suggestions or something else?

c++ lessons – Intro

As the title may suggest, I’m going to start with some c++ lessons.
I will start with some basic lessons, like finding a letter in a 2 dimensional array.
But will progress to something more advanced like building a Object Oriented airplane passenger system.

First lesson will be posted soon!

Mysql backup in java

Here is a quick and easy way to make a mysql database backup in java.

“Quick??” I hear you say, yeah thats right.
Find out below how i did it.

public String MakeBackup(){
        String dump = "C:\\mysqldump --host=/*mysql hostname*/ --port=3306 --user=/*mysql username*/ --password=/*mysql password*/ --compact --complete-insert --extended-insert --skip-comments --skip-triggers /*Name of the database to backup*/";

        Process run = Runtime.getRuntime().exec(dump);
        InputStream in = run.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));

        StringBuffer temp = new StringBuffer();

        int count;
        char[] cbuf = new char[BUFFER];

        while ((count = br.read(cbuf, 0, BUFFER)) != -1) {
            temp.append(cbuf, 0, count);
        }

        return temp;
}

What do you need?
mysqldump.exe (can be found in xampp or if you have access to your mysql server it can be found there also)

Now how does it work?

In the dump String you will have to set the location to mysqldump and configure some extra variables (these variables will show determine the final output). Next it will create a process and run the mysqldump.exe, it will catch the output and put it in a string.

Got questions? ask them!