日期:2014-05-20  浏览次数:20719 次

求助:JSP 连接 数据库 出现问题
简单测试JSP,出现问题,JSP代码:

<%@   page   language= "java "   contentType= "text/html;charset=GB2312 "%>
<%@   page   import= "java.sql.* "%>  
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=ISO-8859-1 ">
<title> Insert   title   here </title>
</head>
<body>
<%  
  String   memberName   =   null;      
  int   logontimes   =   -1;                        
  ResultSet   rs   =   null;
  try   {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
}
catch(java.lang.ClassNotFoundException   e){
System.err.println(e.getMessage());
};
try{
Connection   conn   =   DriverManager.getConnection( "jdbc:odbc:My_Book ");
Statement   stmt   =   conn.createStatement();
String   strSQL=   "SELECT   logon,name   FROM   buyinfo   WHERE   ID   =   'wow '   AND   pwd   =   '123 ' ";
rs   =   stmt.executeQuery(strSQL);

while   (rs.next()){
logontimes=rs.getInt( "logon ");
memberName=rs.getString( "name ");  
}  

stmt.close();
conn.close();

}
catch(SQLException   e){
System.err.println(   e.getMessage());
}
%>
Logon:
<%=logontimes%>
Name:
<%=memberName   %>

</body>
</html>

应该输出结果是Logon:   11   Name:   wow  

但实际上输出却是   Logon:   -1   Name:   null  

请问这是什么地方出的问题?

补充一下
我的环境是:Tomcat6.0   数据库是Access,
数据库在JAVA程序下访问正常,只是在JSP情况下不能正常。


------解决方案--------------------
原来又开了一贴~~

SELECT logon,name FROM buyinfo WHERE ID = 'wow ' AND pwd = '123 '
这句话直接在数据库控制台执行有返回结果吗?