Click here to Skip to main content
11,640,861 members (60,845 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Eclipse
I am trying to connect to database in eclipse to execute a simple login application in which if suppose if login credentials are correct then it will redirect to some other page or else it will tell as incorrect details.

public class DBConnection {
 
	
	static Connection con = null;
	
	public DBConnection()
	{
		
	}
	public static Connection getConnection() throws SQLException
	///public static void main(String[] args) throws ClassNotFoundException, SQLException
	{
		String url = "jdbc:oracle:thin:@localhost:1521:XE";
		String uname = "system";
		String pwd = "password";
			
		try
		{
			//REGISTER DRIVER
			Class.forName("oracle.jdbc.driver.OracleDriver");
			System.out.println("Driver registered successfully..");
			System.out.println();
			//ESTABLISH CONNECTION
			con = DriverManager.getConnection(url, uname, pwd);
			System.out.println("Connection established successfully..");
			System.out.println();	
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return con;
	}	
	public void closeAll()
	{
		try
		{
			con.close();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		
	}
}
 


while running the login pagae ,in console it is saying
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
and

in that

java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)

Please tell me the solution
Posted 4-Feb-13 23:21pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to add the jar containing oracle.jdbc.driver.OracleDriver to the classpath.

If you can't find that on your hard drive you should be able to get it from here; http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html[^]

/Fredrik
  Permalink  
v2
Comments
vinod.sambangi at 5-Feb-13 6:51am
   
Can you please tell me ,what is the name of the jar file and where i can add that jar file.Please tell me .
Fredrik Bornander at 5-Feb-13 7:07am
   
I've added a link.
vinod.sambangi at 5-Feb-13 8:22am
   
Thank you
Fredrik Bornander at 5-Feb-13 8:44am
   
You should mark the answer as Accepted if it solved your problem so that we can close the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mika Wendelius 380
1 OriginalGriff 205
2 DamithSL 153
3 CPallini 125
4 Afzaal Ahmad Zeeshan 124
0 Mika Wendelius 370
1 OriginalGriff 205
2 CPallini 125
3 DamithSL 105
4 Afzaal Ahmad Zeeshan 70


Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100