JSP connection all kinds of database Daquan (next)
Last Update:2017-02-28
Source: Internet
Author: User
js| Data | Database Four, JSP connection Informix database
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 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 ("Successful database operation, congratulations");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
</html>
Five, JSP connect 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: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 ("Successful database operation, congratulations");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
</html>
Six, JSP connection 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 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 ("Successful database operation, congratulations");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
</html>
Seven, JSP connection 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 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 ("Successful database operation, congratulations");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
</html> (Code Lab)