This kind of database logic is all
JSP
It is not a good practice, as a study can do this, to a certain level, you can consider
MVC
Model development. When practicing the following code, it will definitely
JDBC
The driver is placed in the server's class path TestsqlServer.jsp:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<% Class.Forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). Newinstance ();
String Url = "JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = PUBS";
String User = "***";
String password = "*******";
Connection conn = drivermanager.getConnection (URL, User, Password);
Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_Updata);
String SQL = "SELECT * from authors";
ResultSet RS = Stmt.executeQuery (SQL);
While (rs.next ()) {%>
Your first field content is: <% = rs.getstring (1)%>
Your second field content is: <% = rs.getstring (2)%>
<%}%>
<% out.print ("Database operation is successful, congratulations!");%>
<% rs.close ();
Stmt.close ();
CONN.CLOSE ();
%>
body>
html> Put the testsqlserver.jsp into the JSP server such as Tomcat's publishing directory, restart the server, from the browser, you should see the results of the retrieval database.