Friday, July 30, 2010

Java Database Connectivity with MS Access --- Part 3

Now lets see how the program goes: I have considered a simple Java program that lists all the students in the "StudentInfo" database. The program is given below:

import java.sql.*;
public class AccessData {
    public static void main(String args[])
    {
        try
        {
            // Load the driver
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            // Database Connectivity
            Connection con = DriverManager.getConnection("jdbc:odbc:StudentInfo");
            System.out.println("Connected to MS Access");

            // Running a query
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery("select StudentID,Name from StudentInfo");
            while(rs.next()){
                System.out.print(rs.getInt(1)+"::");
                System.out.println(rs.getString(2));
            }           
            rs.close(); // Close the ResultSet
            st.close(); // Close the statement
        }
        catch(Exception e)
        {
            System.out.print(e.getMessage());
        }
    }
}
The output would look like this:

Java Database Connectivity with MS Access --- Part 2

After the creation of the table (in MS Access) and DSN, we should now write a program in Java which connects to this database.
  • As we use SQL statements in the program we have to import the package java.sql.* by the  statement: import java.sql.*; 
  • In any JDBC program, first the driver has to be loaded which is done  by: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
  • Now the driver manager gets connection to the database by the following statement:           Connection con=DriverManager.getConnection ("jdbc:odbc:StudentInfo") ;       Here, "StudentInfo" is the Data Source Name and we are connecting through JDBC-ODBC Bridge Driver. So, the database URL is "jdbc:odbc:StudentInfo". There is no username and password given in this function. Only the database URL is given.
  •  Make sure that the entire program has good Exception handling as the code throws "SQLException".

Java Database Connectivity with MS Access --- Part 1

It is very easy to make a Java program talk to database on Microsoft Access. Here, we connect the Java program to the database by JDBC-ODBC Bridge Driver.
We do not need any JAR files to be included as JDBC is a part of Java API and the connection is through JDBC-ODBC Bridge Driver.
Suppose we have a database in MS Access as given below:


Save this database in "accdb" or "mdb" format. As we are connecting through JDBC-ODBC Birdge driver, we have to create Data Source Name (DSN) for the respective database. The steps for creating a DSN is as follows:
  1. Open "Control Panel" ----  "Administrative Tools" ---- "Data Sources (ODBC)". You get a window like this:
  2. Now click on the "Add" Button which would then look like:
  3. Select "Microsoft Access Driver (*.mdb, *.accdb)" option and click on "Finish" button which invokes one more wizard where you are supposed to give the "Data source name" and select the database file (.mdb or .accdb). After selecting the database where you stored the table, click OK and the DSN named "StudentInfo" is created.

Making Internet faster in Ubuntu 10.04

Many Ubuntu users have complained that the Internet is slow in 10.04 Lucid Lynx. If this is the case with you too, then follow the steps given below:
  1. Try another browser preferably Chromium Web Browser (Google chrome) from the Ubuntu Software Center. Slow Internet is a problem especially in Mozilla firefox and not in other Web Browsers.
  2. If you want to stick to Mozilla Firefox only, then type in the address bar: "about:config" and then make some changes in the configurations:
  • First disable IPv6 in Firefox. Disabling IPv6 allows you fast Internet. Type the text in the filter as "network.dns.disableIPv6" and set the value to TRUE.
  • Similarly, type in the Filter, "network.http.pipelining" and set its value to TRUE. Now type "network.http.proxy.pipelining" in the Filter and set its value to TRUE.
  • Now the last thing to modify in the configurations is to search for "network.http.pipelining.maxrequests" and change the maximum requests to 8 or 10.
     You are done with it. Now enjoy fast Internet.

Tuesday, July 27, 2010

Disable Google chat in GMail easily

Disabling the google chat in Gmail is a very easy and can be done by even Computer beginners. Time mismatch between the GMail server time and the system time would just do the trick with ease. The GMail server checks for the correct date in the system's date and if it is right then the chat will work as usual. But now, if there is a wide disparity in the system time and the GMail server time then the chat would simply be disabled. So, the steps to be followed are:
  1. Change your system date and time to 1 year before the actual date. For example, if the date is 11-07-2010 (DD-MM-YYYY), you need to change it to July 2009. Remember that you need the administrator privileges.
  2. Login into your gmail account with your username and passsword and you would see that the chat is acutally disabled.
       Enjoy this new trick.

Saturday, July 24, 2010

Java Tips: How to use Grid Layout in Java Swing.

They are many types of layouts in Java. But arranging in a tabular order needs us to use Grid Layout. Grid layout in Java Swing is something in a frame that arranges the components in the form of rows and columns. The size of the components, especially buttons, text boxes change as we resize the actual JFrame window. So, when the window is maximised, the components will be distributed accordingly resulting in unusual look and feel. For example, just imagine you have added 4 buttons to a frame by Grid Layout. You would see everything on the frame filled with buttons. This is very awkward to view and has to be avoided.

Thus, it is necessary to fix the components' sizes according to the application or the program. That is, grid layout is good looking as far as the components are of sufficient size not large and not small. In addition to the way the components size is, the resizing of the frame would make it look very awkward which results in the end-user dissatisfaction and an ugly user interface.

Fortunately, there is a solution to this problem. There are two things which you have to remember while using the Grid Layout in Swing.
  1. Set the borders of the frame so, that the components are of good size. This can be done by this piece of code:
    setBorder(BorderFactory.createEmptyBorder(top_margin, left_margin, bottom_margin, right_margin));
  2. After setting the borders, you have to decide the size that the JFrame should be. You can set size by using setSize(width,height).
  3. The most important thing in this discussion is to avoid it from being resized. You can avoid resizing of frame window by the following function: setResizable(false);
Now , you can enjoy all the privileges that Grid Layout provides without being much concerned about the look and feel.

C Program to print your name without using semicolon

I just wondered if I could really write this program. But on rethinking, I found it to be easy. Given below is the C program to print name without using semicolon:


int main()
{
          if(printf("Sai Ravi Kiran \n"))
          {
          }
}


A silly mistake such as omitting the curly braces in the empty "if" block would prove expensive as it is a compilation time error.

Time mismatch could be expensive in Ubuntu 10.04.

Set your system time correctly and give necessary details including your location so that you would not get worried with this particular issue. Ubuntu 10.04 has got something very irritating as it is robust with the match between the system time and the actual time.

When I got my Ubuntu 10.04 reinstalled, this particular aspect just made me worry a bit. I ignored the system time and wanted to install some essential softwares. So, far so good, but now started the actual trouble. There was no "Install" button/option available for the softwares in the "Ubuntu software center". The softwares can be installed from archive files after downloading the files from the respective websites. But that just is not easy as many installations in Ubuntu are difficult unless they are the debian packages. Going with the software center reduces both your time and effort. I was cornered with "Install" button not provided as I couldn't find the reason for this. Upto some half an hour or so, I could not install anything onto my Ubuntu system. I then left it aside and changed my system time to the actual time. Then, when I restarted Software center I was able to download the softwares without any problem as "Install" option reappeared.

There are some other disadvantages if you don't set the time correctly.
  1. Slow Internet --- I must say dead slow. It took about one and a half minute to open "google.com".
  2. Full System utilization even though the system is idle not doing any job. The system monitor showing the processor status to be 100% in use even though it is not used.
So, beware with this very disadvantage of Ubuntu. Double-check your system time.

Thursday, July 1, 2010

Shortcut to logout from Ubuntu

              You can logout of Ubuntu 10.04 just by hitting Ctrl + Alt + Backspace. But this has to be enabled to be used for killing the X-server. For this purpose, the following rules have to be followed in sequence:
  • Select “System”->”Preferences”->”Keyboard”.
  • Select the “Layouts” tab and click on the “Layout Options” button.
  • Select “Key sequence to kill the X server” and enable “Control + Alt + Backspace”.
You are done with this new shortcut.

Controlling the system while you are on Ubuntu

Any Windows user would suggest to hit Ctrl + Alt + Del which opens the Windows Task manager when an application becomes unresponsive. This manager contains the information of the running tasks, processes, networking and so on.

Similarly, in Ubuntu also we have such a manager which gives the details of various aspects like processes, networking etc., In Ubuntu, it is called "System Monitor". When an application becomes unresponsive in Ubuntu, then I would suggest you to use one of these methods:
  1. Goto System -> Administration -> System Monitor and kill the process which is unresponsive.
  2. Open Application -> Accessories -> Terminal and type "killall " and you are done with it.
  3. Use "Force Quit" applet.

What's not so good in Ubuntu 10.04

I have mentioned the new things that are added in Ubuntu 10.04. On the flip side, I felt some of the features were missing from the previous editions.

The first thing is lack of default support for editing images. It has definitely got F-Spot Photo Manager which can manage picture editing to a certain extent. But the powerful "Gimp"  is missing. This piece of software was included in the previous versions of Ubuntu, by default.

The second thing is the Ubuntu software center. It has improved a lot over the previous versions especially in the categorisation of software. But the exact detailed status is not shown while a software is being downloaded and installed. For example, the information about a software such as the space it occupies are not known to the user.

Related Posts Plugin for WordPress, Blogger...