Sunday, September 19, 2010

Using NetBeans Database Tools

Many IDEs have the option of accessing the database and running commands in SQL. Besides this, these IDEs allow the operations to be done on the database, thus making everything at a single place (IDE), rather than switching between the DBMS and IDE continuously.

IBM RAD has this feature of Database Design, accessing databases, tables and schema from itself. Now let us look into the database access with the DBMS from NetBeans. We need to add a database connection before we do anything on the database in the IDE. For the database connection, add a new Driver in the "Drivers" node in the "Services" view (the one that is used for JDBC purposes. Add the JAR file that is used.).





The NetBeans IDE has 3 views on the left side of the main editor:
1. Projects,
2. Files and
3. Services.

Go to the Services view, right click on "Databases" node and select "New Connection".



Now a wizard pops up which asks you to enter the details of the Database connection and the Database. The JDBC URL is also shown in the last text box. Double check whether this database URL is correct or not.




After entering all the details correctly, click on OK and select the schema in the next wizard and click OK.




The Database is configured in NetBeans IDE. Make sure that the one you have added now is listed in the Databases node.




Now we can execute the SQL commands on the Database in NetBeans IDE. Right click on the Database and select "Execute Command".




As soon as you do this, the editor can be used for SQL statements. Enter the commands and see the results down under the editor. You have many buttons readily available and you can make use of all those things. Some of them are:
  1. Run SQL Button
  2. SQL History Button
  3. Inserting and Deleting rows in a table
  4. Truncating a table
  5. Committing changes
  6. Refreshing the results and so on.....



    An IDE has everything within it and all the IDEs are meant for productivity enhancement. But don't think that IDE does everything for you. It makes your life easy. Using IDE is not a crime especially after one gets some clear idea of a programming language. When you use an IDE to do a project, you are doing the project and not the IDE. Using Notepad is not always the best way to do things especially after a person is aware of the syntaxes in a programming language.
    Use IDEs to the fullest by knowing them to the fullest.

    Friday, August 20, 2010

    Text mode Web Browsers in Ubuntu

    Ubuntu Linux has Mozilla Firefox as its default web browser. But, I feel among the modern web-broswers, Chromium Web Browser (Google Chrome) works better than Firefox as far as Ubuntu is concerned. Mozilla Firefox gives slow Internet on Lucid Lynx (Ubuntu 10.04). However, this problem seems to be solved as Maverick Meerkat (Ubuntu 10.10) has come up with a nice fast Internet. Now, coming to the actual discussion, Ubuntu has two types of web-browsers predominantly which are listed below:
    1. Graphical-based Web Browsers
    2. Text-based Web Browsers
    There are two text based web browsers that I mainly used:
    1. ELinks Web Browser
    2. Links Web Browser 

    ELinks Web Browser:


    The ELinks Web Browser supports only text based browsing and pictures are not displayed. ELinks is a feature-rich program for browsing the web in text mode.  It is like enhanced Lynx and Links. The navigation of the web pages is done through space (Page Down) and b (Page Up); Up and down arrows predominantly. Remember that this browser accommodates the contents of a website much like the "more" in UNIX. The URL of the currently viewed web page is not seen anywhere in the browser. When you click on the upper part of the Browser you get the menu bar.




    Links Web Browser:


    Links is a graphics and text mode WWW browser, similar to Lynx. It displays tables, frames, downloads on background, uses HTTP/1.1 keepalive connections. In graphics mode it displays PNG, JPEG, GIF, TIFF, and XBM pictures, runs external bindings on other types, and features anti-aliased font, smooth image zooming, 48-bit dithering, and gamma and aspect ratio correction. But the content is not well-organized a handicap when compared to the contemporary Web Browsers. The navigation is similar to the way as it is in other web browsers. The URL is shown at the top-right of the window. Take a look at the Yahoo home page viewed in the Links Web Browser.

    Thursday, August 19, 2010

    Switching between the X Window mode and the Command-line mode

    Not many would like to work with the command-line in Linux (Ubuntu), but there may be a few geeks who want to try the command-line to really learn the commands. The third type of users want to use both the X-Window mode and the Command-line mode. The present post is specially targeted to such a kind of users.

    To go to the command-line mode from the X window system, press the keys Ctrl+Alt+(F1-F6). Any one of the Function keys in between F1 and F6 is alright. Now for suppose, you want to switch to the graphical mode (X Window system) for some purpose, you can do with an easy shortcut Ctrl+Alt+F7.
       Switching from X window mode to command-line mode -- Ctrl+Alt+(F1-F6).
       Switching from command-line mode to X window mode -- Ctrl+Alt+F7.

    main() function called inside main() definition --- C Language

    Many think that when the main() function call inside the main(), recursion goes on infinite times. But it is not true as such. It is always  important to know how function calling and recursion works. The function calls work with the help of a stack by PUSHing all the functions to a stack and POPing the functions from the stack when they are executed. The following figure gives the complete picture of this working. When a function "func1()" is called from within the "main()" method, the "func1()" is PUSHed onto the stack. Similar is the case with the function "func2()". When the function "func2()" gets completed, it is POPed from the stack. The function calls take place until the stack overflow occurs, that is until the stack is completely filled with the functions. This implies that the recursion without a suitable condition takes place not infinite times but stack size times.
       

    This particular experiment when conducted, compiles successfully but it suffers from a run time error.

    Lets have a look at the functionality of this entire concept and thus decide the output of the program. We also experiment on the number of times the function is called. The entire simulation is with the help of a simple program as given below:

    #include "stdio.h"
    int i=0;
    int main()
    {
                i++;
                printf(" %d\n",i);
                main();           /* Call main() inside main() */
                return 0;
    }

    Now,in the above program the value of "i" signifies the number of times the function is called.

    First, I considered running this program on Turbo C on Windows platform, where the size of a variable of type "int" is 2 bytes. When I ran this program, the function got called around 15000 times and then the compiler crashed with the error message in the image shown below:
    The next time I tried the same program on GNU C compiler on Ubuntu 10.04, where the size of a variable of type "int" is 4 bytes. Now when the program is compiled, it returned successful compilation.



    But when it is run, a runtime error was issued as "Segmentation fault". The error message in the dialog box for Turbo C also indicated the same thing.

    Now what is this segmentation fault? It is an error that occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed. It occurred in this case due to the stack overflow. So, main() called inside main() gives segmentation fault.

    The number of times the function call took place varies continuously between two executions of the program. In Turbo C, the number of times the function call took place is around 16000 while in GNU C Compiler, this figure is around 327000.

    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.

    Wednesday, June 23, 2010

    Some Java script tricks

    • Edit the content of a web page:
      • By setting contentEditable to true, we can change the content of a web page.
      • Type javascript:document.body.contentEditable='true' in the address bar of your web browser. Not only to body, this can be applied to a wide range of tags.
      • Can check the status of contentEditable by isContentEditable. For example, javascript:document.body.isContentEditable to check the status of body tag.
    • Avoid page refreshing:
      • Typing javascript:void(0) in the address bar avoids page refreshing. void should be used with a number. That is, the parameter of zero is compulsory.
      • Therefore, to alter the content of web pages this has to be added to take the effect of the content to be edited. The whole thing now becomes something put down this way: javascript:document.body.contentEditable='true';void(0).
    • Knowing IP address:
      •  "ip" gives the IP address. For example, "javascript:alert(ip)" would give the IP address of the client.

    What's new in Ubuntu 10.04

    I found these very much interesting in Ubuntu 10.04 over the previous versions.

    1. Security:
                        The security levels in Ubuntu 10.04 have been increased. Firstly, a "root" account cannot be created under any circumstances, thus forcing us to use only the normal account. However, we can make installations using that. But a direct "root" account is not available.
                     
    2. Messaging:
                  I think this field has got a wide improvement over the previous versions. It makes audio and video calling very easy. In addition to this, Social Gibber client is also installed by default, to view microblogs such as twitter and other social networking sites.

    3. Networking:
                         I found networking has improved over Ubuntu 9.10. This previous version only had connection through Internet by command line. There are bugs in Network Manager in Ubuntu 9.10 especially when connecting by DSL. But these bugs are rectified in Ubuntu 10.04.

    4. Startup:
                    Startup time has decreased and the operating system loads within no time. Quick startup definitely gives it an extra edge over the previous versions. Other softwares also seemed to start in quick time.

    5. Games:
                       The games have also been changed. There are more logical games than the other conventional card and arcade games.

    6. Other improvements:
    • Open Office 3.2 is used in this operating system. It starts very quickly and has many additional options over the previous versions.
    • Graphics drivers are installed automatically along with the operating system.
    • The new sound recorder is working well. There were some bugs in Ubuntu 8.10.
    • "Add or Remove programs" has been changed to "Ubuntu Software Center", leading to better categorization. The default programs can also be removed from the system, while this was not possible in Ubuntu 8.10.

    Sunday, January 17, 2010

    Differences between a compiler and an interpreter

    1. A compiler first takes in the entire program, checks for errors, compiles it and then executes it. Whereas, an interpreter does this line by line, so it takes one line, checks it for errors and then executes it.
    2. In compiler, the resulting executable is some form of machine- specific binary code. In an interpreter, the resulting code is some sort of intermediate code.
    3. As a compiler executes the entire program at a time, it operates fast. Interpreter takes one line at a time and so, its tradeoff is slow.
    4. A compiler spends a lot of time analyzing and processing the program. An interpreter spends relatively little time is spent analyzing and processing the program.
    5. Program Execution is faster in compiler than in interpreter.
    6. Interaction level is high in interpreter than in compiler.
    7. In a production environment where throughput is more critical, a compiled language is preferred. Any high-level language can either be interpreted or compiled.
    8. An interpreter lets the programmer know immediately when and where problems exist in the code; compiled programs make the programmer wait until the program is complete.
    9. Literally, a compiler is a static interpreter. An interpreter is a dynamic compiler.
    10. Example for compiler: C, C++. Example for interpreter: Perl.
    Related Posts Plugin for WordPress, Blogger...