Life in code, apps and OS's

Archive for November 2008

Whilst doing my usual browsing the net today, I found an excelent tutorial on HowToForge.net that shows how someone can image a linux partition using CloneZilla.

CloneZilla is an Open-source alternative to Norton Ghost, The CloneZilla website can be found at the following URL:

http://clonezilla.org/

HowToForge have an excelent tutorial which can be found at the following URL:-

http://howtoforge.net/back-up-restore-hard-drives-and-partitions-with-clonezilla-live

To sum it all up, CloneZilla enables you to do the following tasks…

  • Backup the following file systems ext2, ext3, reiserfs, xfs, jfs of GNU/Linux, FAT, NTFS of MS Windows, and HFS+ of Mac OS.
  • CloneZilla can either image from HDD to Image file or HDD to HDD.
  • CloneZilla can send the image file to either a Samba, NFS or SSH Server.
  • CloneZilla can if selected break the image files up into smaller chunks eg. 2.0GB files or 700MB (Whatever you choose)
  • CloneZilla can be downloaded for free and burn to a CD-ROM/DVD.

In the past I have used G4L (Ghost4Linux) which also supports NTFS – The windows file system, although I am now considering switching to CloneZilla mainly as the following features are not supported in G4L (or atleast I’ve never seen them)…

  • Backup to SAMBA (Windows File Server – Basically)
  • Image segmentation – Ability to break up image files into smaller chunks.

Anyway enough of me ranting on!! Enjoy!

Looking over the net for a few MySQL/VB.net related tutorials I came across this tutorial at the MySQL website:-

Loading a search MySQL data with DataGrid in VB.net 2005 (but should work with 2008 too!)
http://dev.mysql.com/tech-resources/articles/ebonat-load-and-search-mysql-data-using-vbnet-2005.html

This also looks rather interesting, Its a GUI for MySQL development (my be worth a look??)
http://toadsoft.com/toadmysql/

Since downloading and installing Microsoft VB .net 2008 Express edition yesterday and then playing with it last night whilst at home I managed to build a simple application to connect to a MySQL database and show table records (with corrisponding data using a ‘JOIN’ statement) and I must say I throughly enjoyed it.

A couple of days ago I started playing with the JAVA JDK6 (Update 10) using NetBeans and although NetBeans comes bundled with a few sample apps even looking at the code I didn’t really understand what the JAVA source was doing however VB.net really did seem simple and I felt that I understood what the code was doing.

I now intend to start and play with VB.net, Create a few application etc.

Since developing software for the internet mainly using PHP as well as ColdFusion I have always used MySQL for a number of reasons really…

  • Supported well by the community
  • Its Opensource (Free)
  • Owned by one of the Technoligy giants (Sun Microsystems)

As I have always really used MySQL and am comfortable with it, I still intend to keep using it and most of my applications I will be building will be using MySQL as its back end. – However now Microsoft have released SQL Server 2008 Express edition which is also freely avaliable (with some limitations however) I may even use that from time to time.

So how is VB .net 2008 going to help me, what will I be using it for?? – Well to be honest I’ve never really gotten into developing System Applications and in the past have dedicated my time to developing Web Applications but everyday I see solutions that I feel would definetly work well in conjunction with certain web applications I have developed in the past for example:-

  • Bug Tracking systems – Client to add a bug directly from a user desktop.
  • Bug Tracking systems – Developers task list application.
  • Social network sites – Instant Messenger based on friends list.
  • Software Deployment suite – Download and install client (running as a service)
  • Corporate Web Applications – BackOffice tool to create, edit and ammend records.

Really the list is endless with what you can do and I intend on furthering my knowledge with this language and implement database connected applications for many of my exisiting projects.

Looking at the following URL, I found it quite interesting as to how VB.net and programming in general connects to a TCP socket to send and retrieve data back and fowards to servers and clients on the interenet, Check out the following URL (is a howto to  make a Messanger service for Windows Servers/Clients…

http://www.vbprogramming.8k.com/tutorials/LocalTCP.htm

This tutorial will read all rows in a MySQL database and print out the resaults.

Create a new Java source file and save it as JdbcExample3.java in the same folder where you’ve been keeping others files for this tutorial. Now copy/paste following code in it:

package com.stardeveloper.example;

import java.sql.*;

public class JdbcExample3 {

  public static void main(String args[]) {
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql:///examples",
        "root", "secret");

      st = con.createStatement();
      rs = st.executeQuery("SELECT user_id, first_name, last_name, " +
        "country_code FROM users");

      while(rs.next()) {
        int userId = rs.getInt(1);
        String firstName = rs.getString(2);
        String lastName = rs.getString(3);
        String countryCode = rs.getString(4);

        System.out.println(userId + ". " + lastName + ", " +
            firstName + " (" + countryCode + ")");
      }

    } catch (Exception e) {
      System.err.println("Exception: " + e.getMessage());
    } finally {
      try {
        if(rs != null)
          rs.close();
        if(st != null)
          st.close();
        if(con != null)
          con.close();
      } catch (SQLException e) {
      }
    }
  }
}

Explanation
First line is the package statement that tells the Java compiler that our JdbcExample3 class belongs to com.stardeveloper.example package.

package com.stardeveloper.example;

Next we import the required JDBC classes from java.sql package.

import java.sql.*;

Next we give a name to our class, i.e. JdbcExample3.

public class JdbcExample3 {
	...
}

Next we create a main() method for our class. This is where our JDBC code will reside.

public static void main(String args[]) {
	...
}

We create 3 variables to hold Connection, Statement and ResultSet objects for us which we’ll create later in a try/catch/finally block.

	Connection con = null;
	Statement st = null;
	ResultSet rs = null;

We then enter a try/catch/finally block. Our data access code will reside in the try block, exception notification code in the catch block and code to close the connection in the finally block.

	try {
		...
	} catch (Exception e) {
      System.err.println("Exception: " + e.getMessage());
	} finally {
		...
	}

First thing we do to display records is to obtain a connection to MySQL database and that we do that my first loading it’s JDBC (Connector/J) driver and then using DriverManager to obtain a connection to our “examples” database. You might want to change the password from “secret” to whatever is your password for ‘root’ account.

	Class.forName("com.mysql.jdbc.Driver").newInstance();
	con = DriverManager.getConnection("jdbc:mysql:///examples",
	  "root", "secret");

Once we are connected, we create a new SQL Statement object.

	st = con.createStatement();

We then execute this statement to obtain a ResultSet which contains all the records from the “users” table and we do that by executing a SELECT SQL statement.

	rs = st.executeQuery("SELECT user_id, first_name, last_name, " +
		"country_code FROM users");

We then iterate through that ResultSet to obtain values for each field of the “users” table. We then print these values on the user console.

	while(rs.next()) {
		int userId = rs.getInt(1);
		String firstName = rs.getString(2);
		String lastName = rs.getString(3);
		String countryCode = rs.getString(4);

		System.out.println(userId + ". " + lastName + ", " +
		firstName + " (" + countryCode + ")");
	}

In the finally block we close off our ResultSet, Statement and Connection objects.

	try {
		if(rs != null)
			rs.close();
		if(st != null)
			st.close();
		if(con != null)
			con.close();
	} catch (SQLException e) {}

Compiling JdbcExample3.java
To compile JdbcExample3.java, execute following command at the command prompt from the folder where JdbcExample3.java is residing:

javac -d . JdbcExample3.java
Command Prompt - Compiling JdbcExample3.java
Command Prompt – Compiling JdbcExample3.java

You should now have JdbcExample3.class file under the com/stardeveloper/example folder.

Running JdbcExample3
Before we run our Java program, make sure that MySQL server is running and that you’ve properly created and setup “examples” database and “users” table. Now to run our Java program, execute following command at the command prompt from the folder from where you compiled JdbcExample3.java:

java com.stardeveloper.example.JdbcExample3
Command Prompt - Running JdbcExample3
Command Prompt – Running JdbcExample3

Congratulations! you’ve successfully been able to display all the records from “users” tables in the MySQL “examples” database using JDBC in your Java program.

Summary
In this tutorial we learned how to display records from a table in a MySQL database using JDBC in a Java program.

In next article we will learn what is java.sql.PreparedStatement and how to make use of it.

I found this website and thought I’d post the URL as I will be checking some of this stuff out soon and was kindly thinking of others who are also looking for Java Tutorials…

http://www.tutorialized.com/tutorials/Java/1

Creating a VB.net web browser is an extremly simple task. So much so that it’s a great way to introduce yourself the the language. We shall be using the full version of Visual Basic .Net 2008, but the express editions will work Perfectly fine. Let’s get started shall we?

First open VB and create a new Windows Forms Application. You should name your application something that is easy to remember so you don’t forgot what the folder is called, in this example I shall name it, creatively, browser.

image

Now you should have a empty .Net window. Here we shall start designing our browser. Using the toolbox on the right (if you can’t see the toolbox you

browserx

can open it with control, alt and x) we want to drag over the ‘Web Browser’ Control, contained in the Common Controls box. By default the Web Browser control will take up the whole application, we want to undock it so click the browser once and find the small arrow on the top right (see image below)

arrow

And then click the ‘Undock in Parent Container’. Now we can grab the edges of the web browser control and change it’s size. Ideally we want something the web browser to leave 60 pixels on the top of the windows application. Think about the browsers you’ve used and leave that amount of space for a toolbar. When you have the size of the browser window you want we need to make it expand when the main window expands. We do this by clicking once again on the browser window, then on the right looking in the properties menu and finding anchor. Here we click the drop down box and select the bottom, left and right and top. This will force the browser to expand to the right, left, bottom and top when the main window expands. Without this the browser would just stay the same size.

anchorx

Now in the space above the browser window we want to drag a Panel. You can catch the panel in the toolbox section, containers. A panel will enable us to collectively manage it’s objects, while also helping in the aspect of design. Resize the panel to hit each of the main windows edges and the very top of the browser element. You can use the arrow keys on the keyboard to align the panel. Once again we want to anchor the panel. This time we want to anchor to the top, right and left. We should now have something very much alike to what’s below

browsera

Now we want users to be able to navigate the browser to certain locations using an address bar. To insert a bar using the toolkit drag a text box into our top container. You can find the text box control in the toolbox, common controls section. We want to move the text box control to the very bottom of our container panel and expand it’s size to around 466 pixels. In the right properties menu we want to rename this text box to navbox.

navbox

Now we need to give the user something to click when he has entered the web URL, so for this we’re going to insert a button. We can once again find the button in the common section of the toolbox. Place this button next to the navigation text box. Rename the button searchbutton, then in the properties menu find the ‘Text’ element and type ‘Go’. For design aspects we will change this buttons flatstyle (once again in the properties menu) to Popup. Now resize the button to be as high as your text box.

Ok I’m sure you want to start coding now so let’s quickly move on to making your collection of form items into a browser! Double click on the Go button you’ve created and we should now be shown the code screen.

VB.net 2008 will automaticlly create some code because you double clicked on the code button, and our cursor should be contained within the Private Sub section of code. Here is where we shall start coding.

WebBrowser1.Navigate(navbox.Text)

Lets explain the above simple but powerful code. We first type WebBrowser1 which is the name of the web browser control we dragged onto the application earlier now we call a properties of the control, in this case we want to navigate the browser window, so, as one would expect we type navigate. Now we use brackets to define the value that we want to send the control. If you wanted to the browser to go to one set location you would use quation marks and then a url, for example

WebBrowser1.Navigate(“http://google.com”)

for example However we want to accept use input from our text box. Because we named this textbox navbox we can call it’s value using navbox.text. This means whatever is in the navbox at the time of the user clicking the button will be used as the value. Because it’s not a text string within the code we do not use the quotation marks.

You can now test your browser to see if you can navigate!

image

If all went well you will be able to navigate to any website. Because it uses the IE control if the user has flash installed the browser will be able to view flash, and do many more things IE can do. Of course our browser is not the most exciting yet is it? Lets add a few more important features for any browser!

First of all lets tackle the all important back button. Without back buttons people will be stuck on certain pages and they would not be able to use the browser effectively at all. For the back button we’re going to add yet another button the the browser, this time above the navigation box. We shall name this button backbutton and have it’s text value as ‘Back’. We shall also add a icon for a better cleaner look. To add a icon we shall click the button once and click the properties window, then find the image option. Click the … next to image which will bring up a window saying select resource and then click the import button and find your back image file. For best results use a 24×24 PNG Transparent button (I use this fantastic one). You now will need to change the TextImageRelation to ImageBeforeText. Now repeat these steps replacing back with forward and TextImageRelation to TextBefore Image.

Let’s get to coding these buttons. Double click the back button to once again return to the code window and type WebBrowser1.GoBack(), do the same for the forward button but replace GoBack with WebBrowser1.GoForward(). That’s all for this sort tutorial, on request I will expand with more features such as a search box, I would love to hear your input!

Click to download the source code!

I would just like to make you aware that the above tutorial is taken from the following URL: http://www.tutorialized.com/view/tutorial/A-VB.net-Web-Browser/38174 I therefore take NO credit for this work, I am only hosting this infomation in the unlikely event that the URL above becomes unavaliable or taken offline.



  • How To Dyndns Ubuntu | Order Goods: […] DynDNS Client Setup on Ubuntu | Life in code, apps and OS’s – May 18, 2008  · 7 Responses to "DynDNS Client Setu
  • lizrandolph10886: Wonderful article! We are linking to this particularly great post on our website.nKeep up the great writing. Click
  • waseem Ahmad: Dear. i have a separate application server and a separate mysql database server. when i want to access the application server to login from the local