如何在oacle中为eclipse提供数据库连接 [英] How to provide Data Base connection in oacle for eclipse
问题描述
我正在尝试连接到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();
}
}
}
运行登录pagae时,在控制台中它是说
java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver
和
in那个
java.lang.Class.forName0(原生方法)
at java.lang.Class.forName(Unknown Source)
请告诉我解决方案
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
推荐答案
你需要添加 jar 包含oracle.jdbc.driver.OracleDriver
到类路径。
如果你找不到它硬盘你应该能从这里得到它; http://www.oracle.com/technetwork/database/enterprise-edition/ jdbc-112010-090769.html [ ^ ]
/ Fredrik
You need to add the jar containingoracle.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
这篇关于如何在oacle中为eclipse提供数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!