Accessing the database encyclopedia in the JSP

Source: Internet
Author: User
Tags datetime db2 informix odbc stmt access database
js| Access | data | Database One, JSP connection 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 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 ("Successful database operation, congratulations");%>


<%rs.close ();


Stmt.close ();


Conn.close ();


%>


</body>


</html>











two, JSP connection 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 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>











three, JSP connection DB2 database


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 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 ("Successful database operation, congratulations");%>


<%rs.close ();


Stmt.close ();


Conn.close ();


%>


</body>


</html>











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 connection Access database


<% @page import= "java.sql.*"


import = "java.util.*"


import = "java.io.*"


import= "java.text.*"


contenttype= "text/html; charset=gb2312 "


buffer= "20KB"


%><%! int all,i,m_count;


String Odbcquery;


Connection Odbcconn;


Statement odbcstmt;


ResultSet Odbcrs;


String username,title,content,work,email,url,time,date;


String datetime;


%>


<%


try{


class.forname ("Sun.jdbc.odbc.JdbcOdbcDriver");


}catch (classnotfoundexception e)


{out.print ("driver does not exist");


}


try{


odbcconn = drivermanager.getconnection ("jdbc:odbc:db1");


odbcstmt = Odbcconn.createstatement ();


odbcquery= "SELECT * from book where datetime>2001-4-26 Order by datetime DESC";


odbcrs=odbcstmt.executequery (odbcquery);


int i=0;


while (i<130) Odbcrs.next ();


while (Odbcrs.next ())


{


//*/////////////////////////Display the contents of the database for the debugger is used//


Int II;


try{


try{


for (ii=1;; ii++)


out.print ("<br>cloumn" +ii+ "is:" +odbcrs.getstring (ii));


}catch (NullPointerException e) {


out.print ("with empty pointers");


}


}catch (SQLException e) {


}


}


Odbcrs.close ();


Odbcstmt.close ();


Odbcconn.close ();


}catch (SQLException e)


{out.print (e);


}


%>











Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.