小鸟迎风甩

博客园 首页 新随笔 联系 订阅 管理
<% 
    Connection con = null; 
Statement stmt = null; 
ResultSet rs = null; 
try { 
Class.forName("oracle.jdbc.driver.OracleDriver"); 
con = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:orcl", "system", "oracle"); 
stmt = con.createStatement(); 
rs = stmt.executeQuery("select EMPNO,ENAME from scott.emp"); 
while (rs.next()){
int empno = rs.getInt("EMPNO");
String ename = rs.getString("ENAME");
   out.println(empno + "  " + ename + "<br>");
 
}
 
}catch (ClassNotFoundException ex) { 
} catch (SQLException e) { 
e.printStackTrace(); 
%> 
出现的问题:
1、各种关键字写错。解决:仔细检查。
2、java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
解决:修改端口,1433修改为1158。开启Oracle的各种服务。但还是出现了下面问题。
3、java.sql.SQLException: Io 异常: Bad packet type
     解决:oracle安装目录下的listener.ora和tnsnames.ora文件中的HOST全部改为:HOST = 127.0.0.1,并且修改代码段中的端口号为     1521
posted on 2012-09-28 23:13  小鸟迎风甩  阅读(234)  评论(0编辑  收藏  举报