<%@ 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以下版本在使用中文時可能會有亂碼