JSP的MS SQL SERVER数据库连接
- 作者:zhaozj
- 发表时间:2020-12-23 10:39
- 来源:未知
<%@ 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=km_news";
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 km_news"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()) {%> ÄúµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º<%=rs.getString(1)%> ÄúµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º<%=rs.getString(2)%> <%}%> <%out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");%> <%rs.close(); stmt.close(); conn.close(); %> </body> </html>