A small instance of connecting the SQLServer database in the JSP page. <% @ Page ContentType = "Text / HTML; Charset = GBK"%>
connection the db title> head> <% @ page import = "java.sql. *" %> // Don't forget to introduce SQL package <% class.forname ("sun.jdbc.jdbcodbcdriver"); string url = "jdbc: odbc: message_dsn"; // Message_DSN For your user data source name; string user = ""; string password = ""; // username and password are set to empty; connection conn = drivermanager.getConnection (URL, User, Password); Statement Stmt = conn .createstatement (); string sql = "select * from message1"; // message1 is a table in the library where the data source is located; ResultSet RS = stmt.executeQuery (SQL); while (rs.next ()) {%> The first string: <% = rs.getstring (1)%>
// Extract the first field in this table THE Second String: <% = rs.getstring (2)%>
// Extract the second field <%}%> <% out.print in the table ("Database Operation, Congratulations on You");%> <% rs.close (); stmt.close (); conn.close ();%> body> html> Open a newly created folder in the Configure Libraries in the Tools in JB, and import three resource packs of SQL Driver in this folder. Restart JB, open Tools / Database Pilot in JB to create a new data source, pay attention to the information of which is not contradictory with the username of your above. Run the above program to get the correct result. This segment code also debugged under Eclipse2.1 and JBoss3.2.1.