JSP連接MS sql2008設置

JSP連接MS sql2008設置

MS SQL2008設置

1、配置MS SQL2008

連接進入MS SQL2008

進行如下設置:

確定

2、開始----程序-----MSsql2005----配置工具----sql server外圍應用配置器

應用----確定即可

3、開始----程序-----MSsql2008-----配置工具----sql server配置管理器

看登錄是否成功

4、將最新的jsp連接MS SQL驅動放入tomcat6.0的lib中

或者eclipse項目的

5、下面是test.jsp代碼:

<%@ pagecontentType="text/html;charset=gb2312"%>

<%@ pageimport="java.sql.*"%>

<html>

<body>

<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();

String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=stu";

//stu爲你的數據庫的

String username="meng";

//剛纔新建MS SQL的用戶名

String password="******";

 //密碼

Connection conn=DriverManager.getConnection(url,username,password);

Statementstmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

String sql="select * fromSC";

 //SC數據庫的一個表名

ResultSetrs=stmt.executeQuery(sql);

while(rs.next()) {%>

您的第一個字段內容爲:<%=rs.getString(1)%>

您的第二個字段內容爲:<%=rs.getString(2)%>

<%}%>

<%out.println("數據庫操作成功,恭喜你");%>

<%rs.close();

stmt.close();

conn.close();

%>

</body>

</html>

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章