<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<html>
<body>
<%
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydatabase";
String username = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from mytable where myname='lzz'");
while(rs.next())
{
out.println(rs.getString(1));
out.println(rs.getString(2));
}
rs.close();
stmt.close();
conn.close();
}catch(Exception e)
{
out.println(e);
}
%>
</body>
</html>
刚上机调了下。。这样应该可以吧。这段代码是对了。楼主不妨根据自己数据库情况参考下。
[[it] 本帖最后由 lzz4438253 于 2008-8-15 21:10 编辑 [/it]]