jsp 连接数据库出错?请大家帮忙一下》
使用oracle 10g 和MSSQL200 都不行??
驱动已考到:web-inf\lib下:
代码如下:
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.*,java.io.* "%>
<html>
<body>
以下是从Ms sql server数据库读取的数据: <hr>
<table border=1>
<tr> <td> id </td> <td> 书名 </td> <td> 出版社 </td> <td> 价格 </td> </tr>
<%! String trans(String chi)
{
String result = null;
byte temp [];
try
{
temp=chi.getBytes( "iso-8859-1 ");
result = new String(temp);
}
catch(Unsupported
EncodingException e)
{
System.out.println (e.toString());
}
return result;
}
%>
<%
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
Connection con=java.sql.DriverManager.getConnection( "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev ", "sa ", " ");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery( "select * from book ");
while(rst.next())
{
out.println( " <tr> ");
out.println( " <td> "+trans(rst.getString( "bookId "))+ " </td> ");
out.println( " <td> "+trans(rst.getString( "bookName "))+ " </td> ");
out.println( " <td> "+trans(rst.getString( "publisher "))+ " </td> ");
out.println( " <td> "+rst.getFloat( "price ")+ " </td> ");
out.println( " </tr> ");
}
//关闭连接、释放资源