Jsp tutorial connecting to mssql server database tutorial and displaying data
Class. forName ("com. microsoft. sqlserver. jdbc. SQLSerDriver ");
String url = "jdbc: microsoft: sqlserver: // 127.0.0.1: 1433 ";
String userName = "sa ";
String pwd = "sa ";
DriverManager. getConnection (url, userName, pwd );
%>
<% @ 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 for your database
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 jobs ";
ResultSet rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %>
Your second field content is: <% = rs. getString (2) %>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>