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 SYBASE database
TestMysql.jsp is as follows:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<% Class.Forname ("com.sybase.jdbc.sybdriver). Newinstance ();
String Url = "JDBC: Sybase: TDS: Localhost: 5007 / TSDATA";
// tsdata is your database name
Properties sysprops = system.getproperties ();
Sysprops.put ("User", "UserID");
Sysprops.put ("Password", "User_Password");
Connection conn = drivermanager.getConnection (URL, SYSPROPS);
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>
6. JSP connection mysql database
TestMysql.jsp is as follows:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<% Class.forName ( "org.gjt.mm.mysql.Driver") newInstance (); String url =. "Jdbc:? Mysql: // localhost / softforum user = soft & password = soft1234 & useUnicode = true & characterEncoding = 8859_1"
// 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>
7. JSP connection PostgreSQL database
TestMysql.jsp is as follows:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<% Class.Forname ("Org.PostgreSql.driver"). NewInstance ();
String Url = "JDBC: PostgreSQL: // localhost / Soft"
// Soft is your database name
String User = "myuser";
String password = "mypassword";
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>