JSP database connection

xiaoxiao2021-03-06  78

First, JSP connects 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 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 for your database name 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 ();

%>

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

%>

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

%>

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 operation is successful, congratulations");%> <% rs.close ();

Stmt.close ();

CONN.CLOSE ();

%>

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

New Post(0)