For the first time, reposted a Java database connection! !

xiaoxiao2021-03-06  37

I. JSP connection Oracle8 / 8i / 9i database (with Thin mode) TestoCle.jsp 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 SID String user to your database = "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 first field content is: <% = rs.getstring (1)% > Your second field content is: <% = rs.getstring (2)%> <%}%> <% out.print ("Database operation success, congratulations");%> <% rs.close ); stmt.close (); conn.close ();%> 2, 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: SQLserve R: // 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") ;%> <% rs.close (); stmt.close (); conn.close ();%> 3, 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 for 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_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, Congratulations");%> <% rs.close (); stmt.close (); Conn.Close ();%> four , JSP connection Informix database Testinformix.jsp is as follows: <% @ Page ContentType = "text / html; charset = GB2312"%> <% @ page import = "java.sql. *"%> <% Class.f orName ( "com.informix.jdbc.IfxDriver") newInstance (); String url =. "jdbc: informix-sqli: //123.45.67.89: 1533 / testDB: INFORMIXSERVER = myserver; user = testuser; password = testpassword"; // TestDb for your database name Connection Conn = DriverManager.getConnection (URL); Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_updatable);

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

New Post(0)