Reposted a Java database connection

xiaoxiao2021-03-06  49

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 ();

%>

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 ();

%>

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 ();

%>

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 ();

%>

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

New Post(0)