oracle数据库连接问题:总提示Statement stmt=conn.createStatement();此处有问题?
<%@pagecontentType="text/html;charset=gb2312"language="java"import="java.sql.*"errorP...
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jsp_oracle</title>
</head>
<body>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE","hr","111");
}
catch(ClassNotFoundException e)
{
out.println("找不到驱动类");
}
catch(SQLException e)
{
out.println("连接数据库失败!");
}
//以上是数据库连接
try
{
Statement stmt=conn.createStatement();//此处总提示有错
String sql="select * from EMPLOYEES WHERE EMPLOYEE_ID=100";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
out.println(rs(0));
out.println(rs(1));
}
}
catch(SQLException e)
{
out.println("查询失败!");
}
%>
</body>
</html> 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jsp_oracle</title>
</head>
<body>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE","hr","111");
}
catch(ClassNotFoundException e)
{
out.println("找不到驱动类");
}
catch(SQLException e)
{
out.println("连接数据库失败!");
}
//以上是数据库连接
try
{
Statement stmt=conn.createStatement();//此处总提示有错
String sql="select * from EMPLOYEES WHERE EMPLOYEE_ID=100";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
out.println(rs(0));
out.println(rs(1));
}
}
catch(SQLException e)
{
out.println("查询失败!");
}
%>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询