040917 R JSP connection database Daquan

xiaoxiao2021-03-06  50

jsp database connection Encyclopedia Issue Date: 2004-08-11 OF: java831 (desired) a, jsp connected Oracle8 / 8i / 9i database (with thin mode) testoracle.jsp 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 Sidstring user = "scott"; string password = "tiger"; connection conn = drivermanager.getConnection (URL, User, Password) ; Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String sql = "select * from test"; ResultSet rs = stmt.executeQuery (sql); while (rs.next ()) {%> your The first field content is: <% = rs.getstring (1)%> Your second field content is: <% = rs.getstring (2)%> <%}%> <% out.print (" Database operation, congratulations / ");%> <% rs.close (); stmt.close (); conn.close ();%> 2, JSP connection SQL Server7.0 / 2000 Database / RTESTSQLSERVER.JSP as follows: <% @ page contenttype = "text / html; charset = GB2312"%> <% @ Page Import = "java.sql. *"%> <% Class .forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). NewInstance (); string url =" JDBC: Microsof T: 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_UPDATABLE); 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 operation is successful, congratulations you /");%> <% rs.close (); stmt.close (); conn.close ();%> 3, JSP connection DB2 database /RTESTDB2.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 For your database name / rstring user = "admin "; String password =" "; Connection conn = DriverManager.getConnection (url, user, password); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); 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 operation is successful, congratulations for you / "); %> %RS.close();stmt.close();stmt.close();stmt.close();stmt.close ();%> 4, JSP connection Informix database /rtestinformix.jsp as follows: <% @ Page ContentType = "text / html; charset = GB2312"%> <% @ page import = "java . SQL. * "%> <% class.forname (" com.informix.j Dbc.ifxdriver "). NewInstance (); string url =" jdbc: informix-sqli: //123.45.67.89: 1533 / testdb: informixserver = myserver; user = testuser; password = testpassword "; // testdb for your database Name / RCONNECTION 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 The two fields are: <% = rs.getstring (2)%> <%}%> <% out.print ("Database operation is successful, congratulations for you / ");% "%RS.Close();stmt .Close (); conn.close ();%> 5, JSP connection sybase database /rtestmysql.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 for your database name / rproperties sysprops = system.getproperties (); sysprops.put (" user "," userid "); sysprops.put (" password "," user_password "," User_Password "); Connection conn = DriverManager.getConnection (url, SysProps); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); 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 operation is successful, congratulations for you / ");% % six, JSP The mysql database / RTESTMYSQL.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"

转载请注明原文地址:https://www.9cbs.com/read-115956.html

New Post(0)