问题描述
- MyEclipse中操作数据库的问题
- 自己写了一个小程序,联系数据库操作的,出现java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at oracle.main(oracle.java:12)
[Ljava.lang.StackTraceElement;@5636bc0a
这个错误,求解答。
程序是这样的import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class oracle{public static final String oracleDriverName = ""oracle.jdbc.OracleDriver"";
public static void main(String []args)
{
try{Class.forName(oracleDriverName);
String racleUrlToConnect = ""jdbc:Oracle:thin:@localhost:1521:orcl"";
String user=""scott"";
String password=""123456"";
Connection myConnection=DriverManager.getConnection(racleUrlToConnectuserpassword);
Statement st=myConnection.createStatement();
ResultSet rs=st.executeQuery(""select * from takes"");
while(rs.next())
{
System.out.println(rs.getString(1)+""t""+rs.getString(2)+""t""+rs.getString(3)+""t""+rs.getString(4)
+""t""+rs.getString(5)+""t""+rs.getString(6));
}
}catch(Exception e)
{
e.printStackTrace();
System.out.println(e.getStackTrace());
}
}
}
解决方案
没有导入oracle的驱动包
解决方案二:
没有导入oracle的驱动包
解决方案三:
class.forName(........jdbc.diver.OracleDriver)
解决方案四:
驱动类应该是oracle.jdbc.driver.OracleDriver;需要导入oracle驱动jar包