First put the JDBC driver into the server's classpath, then build a table test in the database, there are two fields such as Test1, Test2, you can use the following SQL Create Table Test (Test1 varchar (20), TEST2 VARCHAR (20) and then writes a test record to this table, then start our JSP and database trip.
First, JSP connection Oracle8 / 8i / 9i database (with Thin mode)
TestoCle.jsp is as follows:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<% Class.Forname ("Oracle.jdbc.driver.OracleDriver"). NewInstance ();
String Url = "JDBC: Oracle: Thin: @localhost: 1521: Orcl";
// orcl for your database SID
String User = "scott";
String password = "tiger";
Connection conn = drivermanager.getConnection (URL, User, Password);
Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_Updata);
String SQL = "SELECT * from test";
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 Success, Congratulations");%>
<% rs.close ();
Stmt.close ();
CONN.CLOSE ();
%>
body>
html>
Second, JSP connection SQL Server7.0 / 2000 database
Testsqlserver.jsp is as follows:
<% @ 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";
// 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_updata); String SQL = "Select * from test";
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 Success, Congratulations");%>
<% rs.close ();
Stmt.close ();
CONN.CLOSE ();
%>
body>
html>
Third, JSP connection DB2 database
Testdb2.jsp is as follows:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<% Class.forname ("com.ibm.db2.jdbc.app.db2driver") .newinstance ();
String Url = "JDBC: DB2: // LocalHost: 5000 / Sample";
// Sample is your database name
String user = "admin";
String password = ""
Connection conn = drivermanager.getConnection (URL, User, Password);
Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_Updata);
String SQL = "SELECT * from test";
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 Success, Congratulations");%>
<% rs.close ();
Stmt.close ();
CONN.CLOSE ();
%>
body>
html>
Fourth, JSP connection Informix database
Testinformix.jsp is as follows:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<% Class.Forname ("com.informix.jdbc.ifxdriver). Newinstance ();
String URL =
"JDBC: Informix-Sqli: //123.45.67.89: 1533 / testdb: informixserver = myserver; user = testuser; password = TestPassword
// testdb names for your database
Connection conn = drivermanager.getConnection (URL);
Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_Updata);
String SQL = "SELECT * from test";
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 Success, Congratulations");%>
<% rs.close ();
Stmt.close ();
CONN.CLOSE ();
%>
body>
html>
V. JSP connection mysql database
<% @ page language = "java" contenttype = "text / html; charSet = GBK" PageEncoding = "GBK"%>
<% @ Page Import = "java.sql. *"%>
Body {
FONT-SIZE: 10PX;
Color: # 000000;
Background-color: "#ffffff";
TEXT: "# 000000"
Line-height: 15px
Margin-left: 0px;
Margin-top: 0px;
Margin-Right: 0px;
Margin-bottom: 0px;
Word-break: Break-all;
}
style>
<%
String test = "mysql system record";
%>