¡¡¡¡Ò»¡¢jspÁ¬½ÓOracle8/8i/9iÊý¾Ý¿â£¨ÓÃthinģʽ£©
testoracle.jspÈçÏ£º
ÒýÓÃ:£¼%@ 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ΪÄãµÄÊý¾Ý¿âµÄSID
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()) {%£¾
ÄúµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º£¼%=rs.getString(1)%£¾
ÄúµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º£¼%=rs.getString(2)%£¾
£¼%}%£¾
£¼%out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");%£¾
£¼%rs.close();
stmt.close();
conn.close();
%£¾
£¼/body£¾
£¼/html£¾
¡¡¡¡¶þ¡¢jspÁ¬½ÓSql Server7.0/2000Êý¾Ý¿â
testsqlserver.jspÈçÏ£º
ÒýÓÃ:£¼%@ 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ΪÄãµÄÊý¾Ý¿âµÄ
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()) {%£¾
ÄúµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º£¼%=rs.getString(1)%£¾
ÄúµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º£¼%=rs.getString(2)%£¾
£¼%}%£¾
£¼%out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");%£¾
£¼%rs.close();
stmt.close();
conn.close();
%£¾
£¼/body£¾
£¼/html£¾
¡¡¡¡Èý¡¢jspÁ¬½ÓDB2Êý¾Ý¿â
testdb2.jspÈçÏ£º
£¼%@ 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ΪÄãµÄÊý¾Ý¿âÃû
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()) {%£¾
ÄúµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º£¼%=rs.getString(1)%£¾
ÄúµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º£¼%=rs.getString(2)%£¾
£¼%}%£¾
£¼%out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");%£¾
£¼%rs.close();
stmt.close();
conn.close();
%£¾
£¼/body£¾
£¼/html£¾
¡¡¡¡ËÄ¡¢jspÁ¬½ÓInformixÊý¾Ý¿â
testinformix.jspÈçÏ£º
ÒýÓÃ:£¼%@ 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ΪÄãµÄÊý¾Ý¿âÃû
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()) {%£¾
ÄúµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º£¼%=rs.getString(1)%£¾
ÄúµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º£¼%=rs.getString(2)%£¾
£¼%}%£¾
£¼%out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");%£¾
£¼%rs.close();
stmt.close();
conn.close();
%£¾
£¼/body£¾
£¼/html£¾
¡¡¡¡Îå¡¢jspÁ¬½ÓAccessÊý¾Ý¿â
£¼%@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 ("Çý¶¯³ÌÐò²»´æÔÚ");
}
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())
{
//*/////////////////////////ÏÔʾÊý¾Ý¿âµÄÄÚÈÝÓÃÓÚµ÷ÊÔ³ÌÐòÊÇÓÃ//
int ii;
try{
try{
for (ii=1;;ii++)
out.print ("£¼br£¾Cloumn "+ii+" is: "+odbcrs.getString(ii));
}catch (NullPointerException e) {
out.print ("ÓпյÄÖ¸Õë");
}
}catch (SQLException e){
}
}
odbcrs.close();
odbcstmt.close();
odbcconn.close();
}catch (SQLException e)
{ out.print (e);
}
%£¾