Thursday, December 8, 2011

Netbeans installation in Windows 7


                                                       Personally I faced a problem while installing netbeans for the first time in my windows 7 os.But at the same time there were no issues while installing it from my workplace which was also on windows 7. I don't know why that happened anyway I wanted to share the solution to all.
                                                      First case is when you have your environment variable set correctly and even after restarting the system you get an error message while tryng to install netbeans which says jdk not installed .It also suggests to use the --javahome command ,so here it is

  • Start the command prompt and set the path to where your netbeans.exe file exists(Copy it to any of your drives if it is on cd).It may look like D:\Aparna\Softwares>netbeans-7.0.1-ml-windows.exe after this add a 'space' and type --javahome 'space' your path to jdk bin.

D:\Aparna\Softwares>netbeans-7.0.1-ml-windows.exe --javahome "C:\ProgramFiles\Java\                        jdk1.7.0_01\bin"
  • Press enter and your netbeans will start installation.

                                                      The second way as everybody is familiar with is by setting environment variable for java(This didnt work for me in first case ).There are many available resources in the internet explaining how to do it especially the http://java.sun.com .Anyway here is it in my words...

  • Right click on MyComputer and  select Properties->Advanced System settings.From the bottom right corner select Environment Variables.
  • Under system variables select variable with name path and select edit if its existing else create a new variable named path .In variable value paste your path to jdk bin 
  • C:\Program Files\Java\jdk1.7.0_01\bin;.    (Dont forget the ;. at the end)

HAVE A GREAT DAY !

Thursday, December 1, 2011

JavaDB (Client or Network database)


                                           Previously we created an embedded javadb with netbeans.Today i will show you how to create a JavaDB Network database which is very simple


  • Choose  services from the left pane of netbeans(or you can find it in windows menu)Expand  Databases and you will find JavaDB.Right click on that and choose create database
  • Here enter the database name:NEW_DB                                                                       Username:app                                                                                                                Password:app also change the database location if required.Press OK.You can now see a new database and its url along with sample db.
  • Right click on the newly created db url and choose connect.Now that the db is connected we will move on to creating a table in it.
  • On expanding the db url you will see APP in bold.This means that APP is set as the default schema.If not bold right click on it and select set as Default Schema


  1. Expand APP and you will see tables which currently is empty.Right click on tables and choose create tables
  2. Provide table name:Fruits. 
  3. Press Add column button there and create a new column in the table.                                      column name:Name                                                                                                       Type:varchar                                                                                                                                          size:10    Uncheck null and click OK                                                                                                    Create 1 more column with Name: Colour                                                                             Type:varchar                                                                                                                           size:10 .Uncheck all and click OK
  4. Now you can see 2 columns being created Click OK 

  • Inserting data into table.


  1. Right click on the newly created table(Fruits) and select execute command                         INSERT INTO FRUITS VALUES('apple','red')  press run

You can view the table data either using the select * from fruits statement or right click fruits and select view data


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Statement;



public class DB
{
    public static void main(String args [])
    {
     
            try {
               
                Connection con= DriverManager.getConnection("jdbc:derby://localhost:1527/NEW_DB","app","app");
             
             
               Statement stmt=con.createStatement();
           
             
                ResultSet rs=stmt.executeQuery("select * from Fruits");
                System.out.println("Fruit   Colour");
                while(rs.next())
                {
                   System.out.println(rs.getString(1)+"  "+rs.getString(2));
                }
             
            } catch (SQLException err) {
             
               System.out.println(err.getMessage()+ "No matching word in database");
            }
        }
    }
 
As did for the embedded db we have to Add Jar file in libraries(Here use the derbyclient.jar file since its network db)