JSP連接Sql Server數(shù)據(jù)庫示例
2018-07-20 來源:open-open

<%@ 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為你的數(shù)據(jù)庫的 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()) { %> 您的第一個(gè)字段內(nèi)容為:<%=rs.getString(1)%> 您的第二個(gè)字段內(nèi)容為:<%=rs.getString(2)%> <% } %> <% out.print("數(shù)據(jù)庫操作成功,恭喜你"); %> <% rs.close(); stmt.close(); conn.close(); %> </body> </html>
標(biāo)簽: 數(shù)據(jù)庫
版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。
最新資訊
熱門推薦