Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

Java
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

1 solution

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
 
Share this answer
 
v2
Comments
vinod.sambangi 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 5-Feb-13 7:07am    
I've added a link.
vinod.sambangi 5-Feb-13 8:22am    
Thank you
Fredrik Bornander 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900