One, JSP connection oracle8/8i/9i database (with thin mode)
Testoracle.jsp 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 for 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 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 ("successful database operation, congratulations");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
% >
</body >
Second, JSP connection SQL server7.0/2000 database
Testsqlserver.jsp 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's
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 ("successful database operation, congratulations");% >
<%rs.close ();
Stmt.close ();
Conn.close ();
% >
</body >
Third, JSP connection DB2 database
Testdb2.jsp 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 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 ("successful database operation, congratulations");% >
<%rs.close ();
Stmt.close ();
Conn.close ();
% >
</body >
Iv. JSP connection to the Informix database
Testinformix.jsp 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 for 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 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 ("successful database operation, congratulations");% >
<%rs.close ();
Stmt.close ();
Conn.close ();
% >
</body >
V. JSP connection to Sybase database
Testmysql.jsp 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:tds:localhost:5007/tsdata";
Tsdata for 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 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 ("successful database operation, congratulations");% >
<%rs.close ();
Stmt.close ();
Conn.close ();
% >
</body >
Vi. JSP connection MySQL Database
Testmysql.jsp 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 for 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 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 ("successful database operation, congratulations");% >
<%rs.close ();
Stmt.close ();
Conn.close ();
% >
</body >
Vii. JSP Connection PostgreSQL database
Testmysql.jsp 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 for 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 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 ("successful database operation, congratulations");% >
<%rs.close ();
Stmt.close ();
Conn.close ();
% >
</body >