public class Db_try1 {
public static void main(String[] args)
{
String driver="oracle.jdbc.OracleDriver";
String url="jdbc:oracle:thin:@localhost:1521:xe";
String user="admin";
String pass="admin";
String sql="";
Connection conn=null;
try
{
Class.forName(driver);
System.out.println("Connecting to database Student.....");
conn=DriverManager.getConnection(url,user,pass);
Statement stmt = conn.createStatement();
sql="select * from student";
ResultSet rs= stmt.executeQuery(sql);
System.out.println("Reading the data and printing...");
while(rs.next())
{
System.out.println(rs.getInt("id"));
System.out.println(rs.getString(1));
System.out.println(rs.getString("mobile"));
}
rs.close(); stmt.close(); conn.close();
}
catch (Exception e)
{
// TODO Auto-generated catch block
System.out.println("Error found");
e.printStackTrace();
}
}
}
我正在使用 oracle 10g,当我在 netbeans 中单击 test connectin 时,我可以连接到数据库。但是当我运行这段代码时,我得到了异常 classnotfoundexception ..