Tuesday, 19 August 2014

SQLException: No suitable Driver Found for jdbc:oracle:thin:@//localhost:1521/orcl

To solve the above issue the below steps need to be followed :

1> Go to oracle eclipse

2>Select the project you have created ->Right Click -> ->Build Path ->Configure Build path and below page will open :




3>Select : add external jars button and from there choose : ojdbc6.jar downloaded previously.

     How to download :

    Type in google to search for : ojdbc6.jar and download from oracle otn website


4> Now again select the project and try to run the application the mentioned error would not show up again.

Happy Programming!!!!!


How To Write Java Program In Eclipse IDE

Create a Java project. Click the drop down arrow beside the first icon "File" at the top left of the screen called “new.” Select “Java Project." Give your new project a name and click finish. I will call my project "stringconcat" You can see that a new folder with your project name appears in the left hand column



Highlight the folder you have just created. Now click the “new” drop down menu once again. This time, pick "Class." Give your new class a name. For this class, we can simply use the default settings. Click finish and Eclipse will open a new Java class in the program window. I called my class "persons.”


Eclipse automatically creates a class in the program window. My class uses a method called read() to sum two values For those who are interested, I have included the code at the bottom  


ItS is time to create our main method. Go back to the drop down menu called “new” and, once again, pick “Class.” This time, check the box that says “public static void main(String[]args).” This indicates to Eclipse that you want to create a main method. Give your main class a name and click finish. I will call mine person. Eclipse now opens a new tab with your main class.


This main class person  will take input from the user . It then passes this information to the persons  class and gets the calculation. Then the program displays the total.
Code sample :

Main class :

package com.abc.com;
import java.util.Scanner;

public class person {

    /**
     * @param args
     */
    @SuppressWarnings("null")
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        persons p1=new persons();
        Integer x1,x2,x;
        @SuppressWarnings("unused")
        Scanner input=new Scanner(System.in);
        System.out.println("enter a value");
        x1=input.nextInt();
        System.out.println("enter a value");
        x2=input.nextInt();
        x=p1.read(x1, x2);
        String string1,string2;      
        string1="hello";
        string2 ="world";
        System.out.println(x);
        System.out.println(string1 + string2);





Another class receiving value from base class :

package com.cnk.com;

public class persons {
   
    public Integer read(Integer a,Integer b)
    {
        Integer c;
        c=a+b;
        return c;
       
       
    }

}



Compile/Test:

Click the "run" button (which looks like a "play" icon) that is located just above your program window. This action will automatically save and compile your code. Your program will run in the console window just below the program window. Check to see if your program works correctly. 





      










How To Connect To a Database Using Eclipse IDE

Step 1

Open Eclipse IDE and Select Database Perspective (Windows >> Open Perspective >> Other).


Step 2

Create Connection Profile: Here we will create profile for connecting to DB.
Method 1: Right click on “Database Connections” and click New.
Method 2: Click onNew Connection Profilebutton in “Data Source Explorer” view.

Step 3:

Select DB (Oracle in this case) to connect from popup window. And provide connection profile name (JBT in this case).

Click Next. In next screen provide DB connection details as shown below.

Once provide you can check if connection to DB is successful or not by clicking “Test Connection” button as shown above.
If everything is fine it should show Ping Succeed popup window as below. If not then check connection related details.

After providing the connection related details click Finish. If everything is fine then a new Connection profile named JBT will be created in Data Source Explorer view