初学者,连接oracle出现的问题。
我的JSP代码如下:
<h1> 正在测试 </h1>
<%
final String DBDRIVER= "oracle.jdbc.driver.OracleDriver ";
final String DBURL= "jdbc:oracle:thin:@localhost:1158:orcl ";
final String DBUSER= "teacher ";
final String DBPASSWORD= "teacher ";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
String sql= "select * from teacher where id= 'user ' and password= 'aaaa ';
%>
sql: <%=sql%> ------在页面显示查询语句
<%
boolean flag=false;
try{
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
flag=true;
}
rs.close();
stmt.close();
conn.close();
}catch(Exception e){
System.out.println( "conn= "+conn); ------tomcat中显示为空
System.out.println(e);------tomcat中显示:java.sql.SQLException: Io 异常: Bad packet type
}
%>
为什么连接不上数据库?
[解决办法]
试试1521端口!“?