主题:求救:时间紧急,31号就要到了,请有经验的前辈指教.
请帮忙看看下面的程序哪里错了,页面正常显示,但总连不上数据库.
下面上按书名查询代码:
byBookName.jsp
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*" %>
<HTML>
<BODY>
<% // 获取提交的书名
String bookname=request.getParameter("bookname");
if(bookname==null)
{ bookname="";
}
byte b[]=bookname.getBytes("ISO-8859-1");
bookname= new String(b);
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.print("error"+e.toString());
}
try{ con=DriverManager.getConnection("jdbc:odbc:sissy","sissy","");
sql=con.createStatement();
String condition="SELECT * FROM book WHERE bookname = "+"'"+bookname+"'";
rs=sql.executeQuery(condition);
System.out.println("rs");
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"图书编号");
out.print("<TH width=100>"+"书名");
out.print("<TH width=100>"+"作者");
out.print("<TH width=100>"+"出版社");
out.print("<TH width=100>"+"出版日期");
out.print("<TH width=100>"+"类别");
out.print("<TH width=100>"+"价格");
out.print("</TR>");
while(rs.next())
{ out.print("<TR>");
out.print("<TD>"+rs.getString(1)+"</TD>");
out.print("<TD>"+rs.getString(2)+"</TD>");
out.print("<TD>"+rs.getString(3)+"</TD>");
out.print("<TD>"+rs.getString(4)+"</TD>");
out.print("<TD>"+rs.getString(5)+"</TD>");
out.print("<TD>"+rs.getString(6)+"</TD>");
out.print("<TD>"+rs.getString(7)+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
con.close();
}
catch(SQLException e)
{
System.out.print("error"+e.toString());
}
%>
</BODY>
</HTML>
下面上按书名查询代码:
byBookName.jsp
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*" %>
<HTML>
<BODY>
<% // 获取提交的书名
String bookname=request.getParameter("bookname");
if(bookname==null)
{ bookname="";
}
byte b[]=bookname.getBytes("ISO-8859-1");
bookname= new String(b);
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.print("error"+e.toString());
}
try{ con=DriverManager.getConnection("jdbc:odbc:sissy","sissy","");
sql=con.createStatement();
String condition="SELECT * FROM book WHERE bookname = "+"'"+bookname+"'";
rs=sql.executeQuery(condition);
System.out.println("rs");
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"图书编号");
out.print("<TH width=100>"+"书名");
out.print("<TH width=100>"+"作者");
out.print("<TH width=100>"+"出版社");
out.print("<TH width=100>"+"出版日期");
out.print("<TH width=100>"+"类别");
out.print("<TH width=100>"+"价格");
out.print("</TR>");
while(rs.next())
{ out.print("<TR>");
out.print("<TD>"+rs.getString(1)+"</TD>");
out.print("<TD>"+rs.getString(2)+"</TD>");
out.print("<TD>"+rs.getString(3)+"</TD>");
out.print("<TD>"+rs.getString(4)+"</TD>");
out.print("<TD>"+rs.getString(5)+"</TD>");
out.print("<TD>"+rs.getString(6)+"</TD>");
out.print("<TD>"+rs.getString(7)+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
con.close();
}
catch(SQLException e)
{
System.out.print("error"+e.toString());
}
%>
</BODY>
</HTML>