I. jsp connection to oracle8/8i/9i Database (in thin Mode)
Testoracle. jsp is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Body>
<% Class. forName ("oracle. jdbc. driver. OracleDriver"). newInstance ();
String url = "jdbc: oracle: thin :@ localhost: 1521: orcl ";
// Orcl is the SID of your database
String 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 rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %>
Your second field content is: <% = rs. getString (2) %>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>
Ii. jsp connection to SQL Server7.0/2000 database
Testsqlserver. jsp is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Body>
<% Class. forName ("com. microsoft. jdbc. sqlserver. 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_UPDATABLE );
String SQL = "select * from test ";
ResultSet rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %>
Your second field content is: <% = rs. getString (2) %>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>
Iii. Connecting to the DB2 database using JSP
Testdb2.jsp is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Body>
<% 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_UPDATABLE );
String SQL = "select * from test ";
ResultSet rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %>
Your second field content is: <% = rs. getString (2) %>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>
4. Connecting to Informix Database Using JSP
Testinformix. jsp is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<HTML>
<Body>
<% 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 is your database name
Connection conn = drivermanager. getconnection (URL );
Statement stmt = conn. createstatement (resultset. type_scroll_sensitive, resultset. concur_updatable );
String SQL = "select * from test ";
Resultset rs1_stmt.exe cutequery (SQL );
While (Rs. Next () {%>
The content of your first field is: <% = Rs. getstring (1) %>
Your second field content is: <% = Rs. getstring (2) %>
<% }%>
<% Out. Print ("database operation successful, congratulations"); %>
<% Rs. Close ();
Stmt. Close ();
Conn. close ();
%>
</Body>
</Html>
V. jsp connection to Sybase Database
Testmysql. jsp is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Body>
<% Class. forName ("com. sybase. jdbc. SybDriver"). newInstance ();
String url = "jdbc: sybase: TTL: 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_UPDATABLE );
String SQL = "select * from test ";
ResultSet rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %>
Your second field content is: <% = rs. getString (2) %>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>
Vi. jsp connection to MySQL database
Testmysql. jsp is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Body>
<% Class. forName ("org. gjt. mm. mysql. Driver"). newInstance ();
String url = "jdbc: mysql: // localhost/softforum? User = soft & password = soft1234 & useUnicode = true & characterEncoding = 8859_1"
// TestDB is your database name
Connection conn = DriverManager. getConnection (url );
Statement stmt = conn. createStatement (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_UPDATABLE );
String SQL = "select * from test ";
ResultSet rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %>
Your second field content is: <% = rs. getString (2) %>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>
VII. jsp connection to PostgreSQL database
Testmysql. jsp is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Body>
<% 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_updatable );
String SQL = "select * from test ";
Resultset rs1_stmt.exe cutequery (SQL );
While (Rs. Next () {%>
The content of your first field is: <% = Rs. getstring (1) %>
Your second field content is: <% = Rs. getstring (2) %>
<% }%>
<% Out. Print ("database operation successful, congratulations"); %>
<% Rs. Close ();
Stmt. Close ();
Conn. Close ();
%>
</Body>
</Html>