Jsp页面关于JDBC怪问题,快崩溃了,高分求救!

PowerAMD3794 2008-09-07 12:02:33
String sql = "select a.fileid,a.FileTitle,a.folderid,a.fileserial,a.filedate,a.producecompany,";
sql += "a.creator,a.keywords,a.flowfileid,a.secretlevel,b.sendmanid,d.foldername,";
sql += "(select c.levelname from Archive2SecretLevel c where a.secretlevel = c.levelid) as levelname";
sql += " from archive2file a,flowfile b,Archive2Folder d";
sql += " where a.flowfileid = b.fileid";
sql += " and a.folderid = d.folderid";
sql += " and a.fileid in("+Cast._String(getVariable(pageContext,"Form.FileID"))+")";
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=butoa_main","sa","sa");
Statement st = conn.createStatement();
ResultSet rst = st.executeQuery(sql);

out.print(sql);
System.out.println("conn.isClosed()="+conn.isClosed());
System.out.println("*********rst.next()="+rst.next());

if(rst != null){
System.out.println("rs不为空");
}else{
System.out.println("rs为空");
}

while(rst.next()){

System.out.println("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
}
if(rst != null)
rst.close();
if(st != null)
st.close();
if(conn != null)
conn.close();

}catch(Exception e){
}

----------------------------------------------------------
Cast._String(getVariable(pageContext,"Form.FileID")) 这个东西就是一个变量 从上一个页面接到的值

问题是 rs不为空 而 rs.next()返回fslse,sql语句打到页面上 复制到查询分析器 执行没问题

将Cast._String(getVariable(pageContext,"Form.FileID")) 换成一个固定值也没问题

或 sql = "select * from archive2file where fileid in("+Cast._String(getVariable(pageContext,"Form.FileID"))+")"; 也没问题

真闹鬼了!崩溃!

...全文
135 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2008-09-07
  • 打赏
  • 举报
回复
那就是sql语句的问题。另外,最好安装最新的 JDBC 1.2,同时支持Sql 2000和 2005

http://www.microsoft.com/downloads/details.aspx?FamilyID=c47053eb-3b64-4794-950d-81e1ec91c1ba&DisplayLang=zh-cn
PowerAMD3794 2008-09-07
  • 打赏
  • 举报
回复
6楼的

System.out.println("*********rst.next()="+rst.next()); 这行本身已经是false了
lybjust 2008-09-07
  • 打赏
  • 举报
回复
是 有点点奇怪哦
孟子E章 2008-09-07
  • 打赏
  • 举报
回复
System.out.println("*********rst.next()="+rst.next());
//这个语句已经将记录移动了,如果只有一条记录,下面的rst.next()一定是false了



if(rst != null){
System.out.println("rs不为空");
}else{
System.out.println("rs为空");
}

while(rst.next()){

System.out.println("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
}
PowerAMD3794 2008-09-07
  • 打赏
  • 举报
回复
2楼的 我的sql语句和你不一样

另外我的数据库是sqlserver2000
elvihuang 2008-09-07
  • 打赏
  • 举报
回复
别的地方为什么就不能加,
___NULL 2008-09-07
  • 打赏
  • 举报
回复
以下代码使用 MSJDBC 1.2,和楼住略有差别
SQL2005 环境通过
SQL2000 也测试通过
-----------------------------

String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=MyDB;user=sqluser;password=123456";

// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try
{
// Establish the connection.
Class.forName ( "com.microsoft.sqlserver.jdbc.SQLServerDriver" );
con = DriverManager.getConnection ( connectionUrl );

// Create and execute an SQL statement that returns some data.
String SQL = "select * from \"case\"";
stmt = con.createStatement ();
rs = stmt.executeQuery ( SQL );

// Iterate through the data in the result set and display it.
while (rs.next ())
{
System.out.println ( rs.getString ( 1 ) + " " + rs.getString ( 2 ) );
}
} // Handle any errors that may have occurred.
catch (Exception e)
{
// ...
}
// ...
}

----------------------------------------------------

如果数据库是 2000/2005 的话,ResultSet 使用 First 或者 Last 之类的方法则需要如下设置。
stmt = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
sd5816690 2008-09-07
  • 打赏
  • 举报
回复
的确很奇怪,按理说查询分析器执行成功了,上面的 rst 应该有值,
但 next() 返回的居然是false

迷惑中

关注

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧