Posted on 2007-12-07 21:29
yukui 閱讀(176)
評論(0) 編輯 收藏 所屬分類:
技術
jsp連接sql server7.0/2000數據庫
testsqlserver.jsp如下:
<%@ page contenttype='text/html;charset=gb2312'%>
<%@ page import='java.sql.*'%>
<html>
<body>
<%class.forname('com.microsoft.jdbc.sqlserver.sqlserverdriver').newinstance();
string url='jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs';
//pubs為你的數據庫的
string user='sa';
string password='';
connection conn= drivermanager.getconnection(url,user,password);
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
string sql='select * from test';
resultset rs=stmt.executequery(sql);
while(rs.next()) {%>
您的第一個字段內容為:<%=rs.getstring(1)%>
您的第二個字段內容為:<%=rs.getstring(2)%>
<%}%>
<%out.print('數據庫操作成功,恭喜你');%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>