<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="net.sourceforge.jtds.jdbc.Driver.*"%>
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head><title></title></head>
<body>
<%
try{
Connection con;
Statement stmt;
ResultSet rs;
Class.forName("net.sourceforge.jtds.jdbc.Driver");
DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver());
String dbUrl = "jdbc:jtds:sqlserver://localhost:1433/j2eeone;user=sa;password=caicaibao";
//String dbUser = "j2ee";
//String dbPwd = "j2ee";
con = java.sql.DriverManager.getConnection(dbUrl);
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT id,name,title,price FROM books");
out.println("<table border='1' width='400'>");
while(rs.next()){
String col1 = new String(rs.getString(1).getBytes("ISO8859-1"));
String col2 = rs.getString(2);
String col3 = rs.getString(3);
String col4 = rs.getString(4);
out.println("<tr><td>" + col1 + "</td><td>" + col2 + "</td><td>" + col3 + "</td><td>" + col4 + "</td></tr>");
}
out.println("</table>");
rs.close();
stmt.close();
con.close();
}catch(Exception e){
out.println(e.getMessage());
}
%>
</body>
</html>
JTDS下载地址:http://sourceforge.net/project/showfiles.php?group_id=33291
上面通过环境:winxpsp2,java1.4.2,sql server2000 sp3, jtds1.1
注意jtds0.9.1以下版本在使用中文时可能会有乱码
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073