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. *"%> <% string result = "; // Query result string string sql =" Select * from test "; // SQL string // Connection string, format:" JDBC: Database Drive Name: Connection Mode: @ Database Server IP: Port Number: Database SID "String Url =" JDBC: Oracle: Thin: @localhost: 1521: orcl "; String username =" scott "; // User name string password =" tiger "; // password // Create an Oracle database driver instance class.Forname (" Oracle.jdbc.driver.Oracledriver) .newinstance (); // Get a connection with the database connection conn = drivermanager.getConnection (URL, Username, Password); // Create a statement object statement stmt = conn.createstatement (); // Execute SQL statement, return result set ResultSet RS = Stmt.executeQuery (SQL); while (rs.next ()) {result = "/ n first field content:" rgetstring (1) "
";} rs.close (); // Close the result set stmt.close (); // Close the execution statement object conn.close (); // Close the connection with the database>
Second, JSP connection SQL Server7.0 / 2000 database
TestsqlServer.jsp is as follows
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% string sql = "select * from test"; // Connect string, Format: "JDBC: Company Name: Database Drive Name: // Database Server IP: Port Number; DatabaseName = Database Name" String Url = "JDBC: Microsoft: SQLServer: // LocalHost: 1433; DatabaseName = PUBS"; string username = "scott"; String password = "tiger"; Class.forName ( "com.microsoft.jdbc.sqlserver.SQLServerDriver") newInstance ();. Connection conn = DriverManager.getConnection (url, username, password); Statement stmt = conn .createstatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_updatable); ResultSet RS = Stmt.executeQuery (SQL);%>
<% while (rs.next ()) {%> The first field content is: <% = rs.getStrisng (1)%>Testdb2.jsp is as follows:
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% string sql = "select * from test"; // Connect string, Format: "JDBC: Database Drive Name: // Database Server IP: Port Name / Database Name" String Url = "JDBC: DB2: // LocalHost: 5000 / Sample"; string username = "scott"; string password = "Tiger "; Class.forName (" com.ibm.db2.jdbc.app.DB2Driver ") newInstance ();. Connection conn = DriverManager.getConnection (url, username, password); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.concur_updatable; ResultSet RS = Stmt.executeQuery (SQL); rs.close (); stmt.close (); conn.close ();%> 4, JSP connection Informix database
Testinformix.jsp is as follows:
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% string sql = "select * from test"; // Connect string, Format: "JDBC: Database Drive Name: // Database Server IP: Port Number / Database Name: InformixServer = Server Name; User = User Name; Password = Password" String Url = "JDBC: Informix-Sqli: //123.45.67.89 : 1533 / testDB: INFORMIXSERVER = myserver; user = testuser; password = testpassword "; Class.forName (" com.informix.jdbc.IfxDriver ") newInstance (); Connection conn = DriverManager.getConnection (url); Statement stmt =. Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_updata; ResultSet RS = Stmt.executeQuery (SQL); rs.close (); stmt.close (); conn.close ();%>
5. JSP connection Sybase database TestsyBase.jsp is as follows:
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% string sql = "select * from test"; // Connect string, Format: "JDBC: Company Name: Database Drive Name: Database Server IP: Port Name / Database Name" String Url = "JDBC: Sybase: TDS: LocalHost: 5007 / TSData"; Properties Prop = System.getProperties (); Prop. PUT ("User", "userid"); // User name prop.put ("password", "user_password"); // password class.forname ("com.sybase.jdbc.sybdriver). NewInstance (); Connection conn = DriverManager.getConnection (url, prop); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery (sql); rs.close (); stmt.close (); Conn.close ();%> 6, JSP connection mysql database
TestMysql.jsp is as follows:
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% string sql = "select * from test"; // Connect string, Format: "JDBC: Database Drive Name: // Database Server IP / Database Name? User = User Name & Password = Password & Using Unicode = Boolean & Character Coding = Code" String Url = "JDBC: MySQL: // Localhost / Softforum ? user = soft & password = soft1234 & useUnicode = true & characterEncoding = 8859_1 "; String username =" scott "; String password =" tiger "; Class.forName (" org.gjt.mm.mysql.Driver ") newInstance ();. Connection conn = DriverManager.getConnection (url, username, password); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery (sql); rs.close (); stmt.close (); conn .close ();%> 7, JSP connection PostgreSQL database
TestPostgreSql.jsp is as follows:
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% string sql = "select * from test"; // Connect string, Format: "JDBC: Database Drive Name: // Database Server IP / Database Name" String Url = "JDBC: PostgreSQL: // LocalHost / Soft"; string username = "scott"; string password = "tiger"; class.forname ( "" org.postgresql.Driver ") newInstance ();. Connection conn = DriverManager.getConnection (url, username, password); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt. ExecuteQuery (SQL); RS.Close (); stmt.close (); conn.close ();%>