JAVA&JSP高手请进(有关无效索引的问题)
//数据库里面的绝对没有一点问题,··!!!<%@pagelanguage="java"contentType="text/html;charset=GB18030"pa...
//数据库里面的绝对没有一点问题,··!!!
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import = "java.sql.*" %>
<%! String str = ""; %>
<%!
private void tree(Connection conn, int id){
System.out.println(" a run tree()");
Statement stmt = null;
ResultSet rs = null;
try{
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from article where pid ="+id);
while(rs.next()){
str += "<tr><td>"+ rs.getInt("id") +"</td><td>"+ rs.getString("title") + "</td><tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"));
}
}
} catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs != null){
rs.close();
rs = null;
}
if(stmt != null){
stmt.close();
stmt = null;
}
if(conn != null){
conn.close();
conn = null;
}
} catch(SQLException e){
e.printStackTrace();
}
}
}
%>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException e){ e.printStackTrace(); }
try{
conn = DriverManager.getConnection("Jdbc:Odbc:sun","sa","");
stmt = conn.createStatement();
String sql = "";
sql = "select * from article where pid=0";
rs = stmt.executeQuery(sql);
System.out.println(sql);
while(rs.next()){
str += "<tr><td>"+rs.getInt("id")+"</td><td>"+rs.getString("title")+"</td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"));
}
rs.close();
stmt.close();
conn.close();
}
} catch(SQLException e){
e.printStackTrace();
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<table border = "1">
<%= str %>
</table>
</body>
</html>
错误报告如下:java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114) 展开
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import = "java.sql.*" %>
<%! String str = ""; %>
<%!
private void tree(Connection conn, int id){
System.out.println(" a run tree()");
Statement stmt = null;
ResultSet rs = null;
try{
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from article where pid ="+id);
while(rs.next()){
str += "<tr><td>"+ rs.getInt("id") +"</td><td>"+ rs.getString("title") + "</td><tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"));
}
}
} catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs != null){
rs.close();
rs = null;
}
if(stmt != null){
stmt.close();
stmt = null;
}
if(conn != null){
conn.close();
conn = null;
}
} catch(SQLException e){
e.printStackTrace();
}
}
}
%>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException e){ e.printStackTrace(); }
try{
conn = DriverManager.getConnection("Jdbc:Odbc:sun","sa","");
stmt = conn.createStatement();
String sql = "";
sql = "select * from article where pid=0";
rs = stmt.executeQuery(sql);
System.out.println(sql);
while(rs.next()){
str += "<tr><td>"+rs.getInt("id")+"</td><td>"+rs.getString("title")+"</td></tr>";
if(rs.getInt("isleaf")!=0){
tree(conn,rs.getInt("id"));
}
rs.close();
stmt.close();
conn.close();
}
} catch(SQLException e){
e.printStackTrace();
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<table border = "1">
<%= str %>
</table>
</body>
</html>
错误报告如下:java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114) 展开
5个回答
展开全部
在jsp对sqlserver数据库进行数据读取的时候,
必须按照表中列名的顺序读取,否则会出现错误
取数据的时候要按照数据库字段的顺序来取
比如数据库 varchar id
varchar name
varchar address
取的时候一定要按下面顺序来取:
rs.getString("id")
rs.getString("name")
rs.getString("address")
再赋值
String s1=rs.getString("id");
String s2=rs.getString("name");
String s3=rs.getString("address");
之后可以随意顺序使用s1,s2,s3了!
必须按照表中列名的顺序读取,否则会出现错误
取数据的时候要按照数据库字段的顺序来取
比如数据库 varchar id
varchar name
varchar address
取的时候一定要按下面顺序来取:
rs.getString("id")
rs.getString("name")
rs.getString("address")
再赋值
String s1=rs.getString("id");
String s2=rs.getString("name");
String s3=rs.getString("address");
之后可以随意顺序使用s1,s2,s3了!
展开全部
rs = stmt.executeQuery("select * from article where pid ="+id);
这句话有问题吧 没暴黄?还是没看到啊? id 这个变量上面都没有定义啊
你把整个的sql语句打出来看一下吧
这句话有问题吧 没暴黄?还是没看到啊? id 这个变量上面都没有定义啊
你把整个的sql语句打出来看一下吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
rs = stmt.executeQuery("select * from article where pid ="+id); 写错了,少单引号!
rs = stmt.executeQuery("select * from article where pid ='"+id+"'");
rs = stmt.executeQuery("select * from article where pid ='"+id+"'");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
好像是你链接数据库语句有问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码太乱了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询