1, with database software (such as: MySQL) to create a database, the database registered with the database name is just the data created
Library, if it is a data source name, ODBC configuration is required.
2, the driver will be placed in the D:/tomcat 5.5/common/lib or the corresponding development tools of the LIB,
For D:/tomcat 5.5/conf/web.xml modifications, open Web.xml, add the following in front of </web-app>:
<resource-ref>
<description>db connection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Navigate through the folder to D:/tomcat 5.5/conf/catalina/localhost, and find your Web application corresponding to the. XML text
Pieces, such as Root.xml, and add code to the bottom of this file:
Testoracle.jsp is as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<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)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Database operation successful, congratulations/");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
Testsqlserver.jsp is as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<body>
<%class.forname ("Com.microsoft.jdbc.sqlserver.SQLServerDriver"). newinstance ();
String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs";
Pubs for your database of
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)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Database operation successful, congratulations/");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
Third, JSP connection DB2 database
Testdb2.jsp is as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%> <body>
<%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)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Database operation successful, congratulations/");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
Four, JSP connection Informix Database
Testinformix.jsp is as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<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)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Database operation successful, congratulations/");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
Five, JSP connection Sybase database
Testmysql.jsp is as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<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)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Database operation successful, congratulations/");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
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)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Database operation successful, congratulations/");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
Seven, JSP connection PostgreSQL database
Testmysql.jsp is as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<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)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Database operation successful, congratulations/");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.