JSP连接Oracle

<% 
    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

你可能感兴趣的:(oracle)