Wednesday, February 26, 2014

Hoe to Create/Establish a Java--SQL Server Database Connection

Ooo!k! First things first; you have to configure SQL Server, i mean, create an instance (sql server authentication ~>"optional"), Grant permissions, Enable TCP/IP, Get port number then Restart SQL service.
After that, you have to get/download ms sql server jdbc driver. if you already have then, unzip to any dir/location of your choice. all you need is the sqljdbc4.jar OR sqljdbc.jar file. Copy either file, based on you Connection/DBase type, paste on your desktop for easy access.
Next;
Add the sqljdbc.jar file in your 'compile time library'... see example on adding sqljdbc.jar using NetBeans IDE.

From your file menu item, click on "project properties (project_name); 
under categories list, select libraries

Next, click on 'Add JAR/Folder' button the add the sqljdbc.jar file, then click 'Ok'....Up next is your code.

Your code should look similar to the below code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBase {

     public static void main(String [] args) throws SQLException, ClassNotFoundException
     {
        try
        {
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

    String ConnString =  "jdbc:sqlserver://localhost:1433; databaseName= clems; username=Douby;password=clems";

        Connection conn = (DriverManager.getConnection(ConnString));
        Statement stmt = conn.createStatement();
        String sql_stmt = "Select First_Name from Employee";
       ResultSet rs = stmt.executeQuery(sql_stmt);

        while (rs.next())
        {
            String a = rs.getString("First_Name");
            System.out.println(a);
        } 
        }        
        catch (SQLException | ClassNotFoundException sql_cnfe)
        {
            System.out.println(" ClassNotFoundException thrown");
            sql_cnfe.printStackTrace();
        }
    }
  }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Still don't get it? feel free to reach me
   

  


Thursday, February 20, 2014

Microsoft SQL Server, Error: 4064


After creating a new SQL Server Authentication (login and password), you are bound, may be not, to get the above error message "Microsoft SQL Server, Error: 4064". But not to worry, cos problem's solved. All you have to do is first connect using Windows Authentication. Then, On the Object Explorer window, Right click on Server name_type, click on properties ~> Select permissions page, select your login name then Grant permissions i.e. Enable every check Boxes under the Grant column. Reload, Try to connect again.

Solved. Still not connecting? comment.

How to Create a new SQL Server Authentication login
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
follow the below steps:

  • Open object explorer, connect using windows authentication
  • Back to Object explorer, Right click on Security ~> New ~> Login
  • Select SQL Server Authentication r.button
  • Enter login details (name and password) then click 'OK' 
If you get error 4064 when trying to connect with your newly created login details, then, read the above.

Wednesday, February 12, 2014

Guidelines for Writing a Perfect Final Year Computer Science Project/Report

Shown below is the Guideline for writing a perfect final year computer science project/report
  • Title Page
Title page, Certification, Dedication, Acknowledgement, Table of content, Abstract
  • Chapter One – Introduction
-          Statement of problem (problem identification) & theory behind the problem
-          Aims/Objectives
-          Scope
-          Methodology
-          Definition of terms
  • Chapter Two – Literature Review
Review of study, review of what has been done in the area of research with technical details
  • Chapter Three – System Analysis and Design
System Analysis
-          System description
-          Historical background of the case study
-          Evaluation of the current system
-          Benefit of the current system
-          Problem of the current system
-          Technical details to solution of the problem
System Design
-          Overview of the new system
-          Output design
-          Input design
-          Database design
-          Process design
** Students are advised to used at least two of the following tools
                     i.            Program flowchart
                    ii.            Data flowchart
                   iii.            Algorithms
                  iv.            Uml e.t.c
  • Chapter Four – System Implementation and Documentation
-          Choice of programming language
-          Choice of DBMS
-          System requirement
-          Hardware requirement
-          Software requirement
-          System testing
-          File conversion
-          System documentation
  • Chapter Five – Summary, Conclusion and Recommendation
-          Summary of findings
-          Limitations
-          Conclusion
-          Recommendation
  • References
  • Appendices
-          Chart/Tables
-          Diagrams
-          Source codes
-          Screen shots





Friday, February 7, 2014

Microsoft SQL Server, Error: 18456

Cannot connect to User_Name-PC
Login failed for User_Name-PC (Microsoft SQL Server, Error: 18456) 













This is one annoying error message you get when trying to connect to an instance of SQL Server BUT, not to worry, COS, problem's solved.
All you have to do is "turn user account control off". Follow the below steps to turn off user account control

Goto Start ~> Control Panel ~> User Account ~> Turn user account control on or off ~> Then, uncheck the 'Use User Account control (UAC) to help protect your computer' check box ~> Click OK, you would get the below message asking for sytem restart, click restart now. thats all. job's DONE.

Thursday, February 6, 2014

Hoe to Create/Establish a VBasic--SQL Server Database Connection



Shown in the above form is a first name, last name and age text boxes named txtFName, txtLName and txtAge respectively. lastly, is the update button named BtnUpdate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Source Code ~> Vbasic 2010 vs Sql Server 2005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Imports System.Data
Imports System.Data.SqlClient

Public Class frm_main  ' Class Begins Here

    ' Declare a new Sql_client_connection = SqlConn
    ' Sql_Command = SqlComm AND
    ' Sql_Connection_String
    Dim SqlConn As New SqlClient.SqlConnection
    Dim SqlComm As New SqlCommand
    ' Data Source = Server Name; Initial Catalog = DataBase Name
    Dim SqlConnString = "Data Source=DOUBRA-PC;Initial Catalog= clems;Integrated Security=True "

    Private Sub frm_main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SqlConn.ConnectionString = SqlConnString
        SqlConn.Open()

    End Sub

    Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click

        SqlComm.CommandText = "Insert into Employee values(' " & txtFName.Text & " ', ' "          & txtLName.Text & " ', ' " & txtAge.Text & " ')"

        SqlComm.CommandType = CommandType.Text
        SqlComm.Connection = SqlConn
        SqlComm.ExecuteNonQuery()

    End Sub
End Class    ' Class Ends Here

Source code screen shot
~~~~~~~~~~~~~~~~










Data base screen shot
~~~~~~~~~~~~


















Still don't get it, watch the below video

Tuesday, February 4, 2014

Hoe to Create/Establish a VBasic--MS Access Database Connection

STEPS
After Designing your form and naming your controls, follow the below steps:

**Double click on any area on your form to display the code window
Outside your class scope, import both system.Data and system.Data.oledb
~~~~~~~~~~~~~~~~~~~                                                                                  
Imports System.Data                                                                         
Imports System.Data.OleDb 
~~~~~~~~~~~~~~~~~~~                                                                                      
**Now, inside your class but outside any method/function, declare a new connection, command and connection string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~                                                            
Dim Conn As New OleDbConnection     
Dim Conn_command As New OleDbCommand                                           
Dim Conn_String = "   ' your connection string "                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~

**Next, under your forms load event, set and open the connection             ~~~~~~~~~~~~~~~~~~~~~~                                                                          
Conn.ConnectionString = Conn_String
Conn.Open()
~~~~~~~~~~~~~~~~~~~~~~                                                                                                       
**Lastly, set your command text, command type, connection AND execute your sql statement                                                                           
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Conn_command.CommandText = " Sql statement "
Conn_command.CommandType = CommandType.Text
Conn_command.Connection = Conn
Conn_command.ExecuteNonQuery()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Still don't get it, see example below
------------------------------
Windows form ~> frm1.vb
------------------------------














First name text box is named txtFirstName
Last name text box is named txtLastName
Address text box is named txtAddress
Phone text box is named txtPhone
Update button is named BtnUpdate

Source Code ~> Designed using vb 2010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' import statements ~> Outside the class scope 
Imports System.Data
Imports System.Data.OleDb
' class begins
Public Class frm_main   
    
    ' NOW Inside the class BUT outside any method scope                                                                  Creat a new Oledb Connection = Access Dbase connection
    Dim Conn As New OleDbConnection

    ' Creat a new Oledb Command
    Dim Conn_command As New OleDbCommand

    'Connection String = The database connection string
    Dim Conn_String = "Provider=Microsoft.Jet.OLEDB.4.0;Data               Source=C:\DBaseFiles\Employee.mdb"
    Private Sub frm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Set the connection String
        Conn.ConnectionString = Conn_String

        'Open the connection 
        Conn.Open()
    End Sub

     ' Click event
    Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click

        Dim Query As String
        Query = "Insert into Emp_PersonalDetails values (' " & txtFirstName.Text & " ', ' " & txtLastName.Text & " ', ' " & txtAddress.Text & " ', ' " & txtPhone.Text & " ')"
        Conn_command.CommandText = Query
        'Set the command type
        Conn_command.CommandType = CommandType.Text
        'Set the connection
        Conn_command.Connection = Conn
        'Execute Query
        Conn_command.ExecuteNonQuery()

         ' Display message     
         Dim msg As String
        msg = MessageBox.Show("Record Updated Succesfully", "Employee DBase")

    End Sub
End Class

Source code screen shot
~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Below is the database view after a record is added/updated:







Still don't get it, watch the below video 

Who is a Software Developer?

A software developer is a person who is responsible to make specialized computer software for a client, or for himself OR herself. 
There are three kinds of software developers:
1. Computer Programmers
2. Software Developers, User Applications
3. Software Developers, Systems
As a software developer in an organization, your job will involve some or more of the following:
• Designing software
• Programming
• Installation
• Configuration
• Customization
• Specification
• Requirements analysis
• Development and refinement of simulations or prototypes
• Feasibility and cost–benefit analysis
• Testing
• Maintenance
In other words, in this technical world, the work of a software developer is extremely important. It also carries good financial benefits.

Monday, January 27, 2014

Factorial (n!), Permutation (nPr) and Combination (nCr) Calculator. "Java Code Snippet"

Factorials { n! ~> pronounced n factorial } are used to compute permutations (nPr) and combinations (nCr). A factorial is the result of multiplying a given number of consecutive integers from 1 to the given number. It is written with the exclamation sign: n! and it is defined as
0! = 1
1! = 1
2! = 2 x 1 = 2
3! = 3 x 2 x 1 = 6
4! = 4 x 3 x 2 x 1 = 24
5! 
5! = 5 x 4 x 3 x 2 x 1 = 120 ...~> and so on   

-----------------------------------
Source Code for calculating n!
-----------------------------------
   import static java.lang.System.out;
      import java.util.Scanner;

     public class factorial
     {  
           public static void main(String[] args)
           {
                       out.print(" Enter your value : ");

                          Scanner in = new Scanner(System.in);
                             int input = in.nextInt();

                         int fac = 1;
                         for(int num = input; num>=1; num--)
                         {
                     fac = fac * num;
                      }
             
            out.printf(" The factorial of %d = %d" , input, fac);
             out.println();
   }
       }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Permutation ~> nPr = n!/(n-r)!
In the context of counting problems, Permutations is the arrangements where the order is important and repetitions or recurrence is not allowed. The number of permutations of n distinct points taken r at a time is written as nPr. Because the number of objects is being arranged cannot exceed total number available. There are n! (n factorial) permutations of n symbols. A r-permutation of n symbols is a permutation of r of them. There are n!/(n - r)! different r-permutations of n symbols. A permutations represented by nPr and calculated from the formula nPr = n!/(n - r)!

------------------------------------
Source Code for calculating nPr
------------------------------------
   import static java.lang.System.out;
      import java.util.Scanner;

      public class nPr
      {
                 // static variables n for the value of n and ...
static int n,r, n_Sub_r;

           public static void main(String[] args)
           {
                     out.print(" Enter the value of n = ");

                       Scanner in1 = new Scanner(System.in);
                             int input1 = in1.nextInt();

                             // saving a copy of input1 which is = n
                             n = input1;

                              // calculating n factorial

                              int nFac = 1;

                              for(int num1 = n; num1 >=1; num1--)
                               {
                                nFac = nFac * num1;
        }

                         out.print("\n Enter the value of r = ");

               Scanner in2 = new Scanner(System.in);
               int input2 = in2.nextInt();

                // saving a copy of input2 which is = r
                                             r = input2;

         // calculating the value of n - r as n_Sub_r
                                        n_Sub_r = (n - r);

                         // calculating n - r factorial
                                 int n_rFac = 1;

         for(int num2 = n_Sub_r; num2 >=1; num2--)
         {
          n_rFac = n_rFac * num2;
         }

                         // calculating (n!/(n-r)!)

                             int result = (nFac / n_rFac);

                           out.printf("\n %dP%d = %d\n\n" , n ,r, result);
          }
           }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Combination~> nCr = n!/(n-r)!r!
Combinations is a method of selecting several items or symbols out of a larger group or a data set, where an order does not matter. The Combination represented by nCr and calculated from the formula nCr = n!/(r!(n - r)!). Each r combination can be arranged in r! different ways. Then the number of r-permutations is equal to the number of r combinations times r!

------------------------------------
Source Code for calculating nCr
------------------------------------
import static java.lang.System.out;
      import java.util.Scanner;

      public class nCr
      {
                 // static variables n for the value of n and ...
static int n,r, n_Sub_r;

           public static void main(String[] args)
           {
                    out.print(" Enter the value of n = ");

                       Scanner in1 = new Scanner(System.in);
                             int input1 = in1.nextInt();

                             // saving a copy of input1 which is = n
                                   n = input1;

                              // calculating n factorial
                                  int nFac = 1;

                              for(int num1 = n; num1 >=1; num1--)
                               {
                                nFac = nFac * num1;
        }

                         out.print("\n Enter the value of r = ");

               Scanner in2 = new Scanner(System.in);
               int input2 = in2.nextInt();

                // saving a copy of input2 which is = r
                                             r = input2;


         // calculating the value of (n - r) as n_Sub_r
                                         n_Sub_r = (n - r);

                                   // calculating n - r factorial
                                         int n_rFac = 1;

         for(int num2 = n_Sub_r; num2 >=1; num2--)
         {
          n_rFac = n_rFac * num2;
         }

                                   // calculating r factorial
     int rFac = 1;

    for(int num3 = r; num3 >=1; num3--)
  {
   rFac = rFac * num3;
  }
                         // calculating (n!/(n-r)!r!)

                         int result = (nFac / (n_rFac * rFac));

                         out.printf("\n %dC%d = %d\n\n" , n ,r, result);
          }
          }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How to use? Simple; copy and paste code in any IDE of your choice, save, compile then run. GOOD LUCK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~