ºìÁªLinuxÃÅ»§
Linux°ïÖú

һЩ³£ÓõÄÔÚjspÖÐÁ¬½ÓÊý¾Ý¿âµÄ·½Ê½

·¢²¼Ê±¼ä:2006-05-22 00:57:48À´Ô´:ºìÁª×÷Õß:cooc
ÏÖÔÚÓкöà³õѧjspµÄÍøÓѾ­³£»áÎÊÊý¾Ý¿âÔõôÁ¬½Ó°¡£¬ÔõôÀϳö´í°¡£¿ËùÒÔÎÒ¼¯ÖеÄÔÚÕâдƪÎÄÕ¹©´ó¼Ò²Î¿¼£¬ÆäʵÕâÖÖ°ÑÊý¾Ý¿âÂß¼­È«²¿·ÅÔÚjspÀïδ±ØÊǺõÄ×ö·¨£¬µ«ÊÇÓÐÀûÓÚ³õѧÕßѧϰ£¬ËùÒÔÎÒ¾ÍÕâÑù×öÁË£¬µ±´ó¼Òѧµ½Ò»¶¨³Ì¶ÈµÄʱºò£¬¿ÉÒÔ¿¼ÂÇÓÃMVCµÄģʽ¿ª·¢¡£ÔÚÁ·Ï°ÕâЩ´úÂëµÄʱºò£¬ÄãÒ»¶¨½«jdbcµÄÇý¶¯³ÌÐò·Åµ½·þÎñÆ÷µÄÀà·¾¶ÀȻºóÒªÔÚÊý¾Ý¿âÀィһ¸ö±ítest,ÓÐÁ½¸ö×ֶαÈÈçΪtest1£¬test2£¬¿ÉÒÔÓÃÏÂÃæSQL½¨

create table test(test1 varchar(20),test2 varchar(20)

È»ºóÏòÕâ¸ö±íдÈëÒ»Ìõ²âÊԼͼ

ÄÇôÏÖÔÚ¿ªÊ¼ÎÒÃǵÄjspºÍÊý¾Ý¿âÖ®Âðɡ£

Ò»¡¢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Á¬½ÓSybaseÊý¾Ý¿â

testmysql.jspÈçÏ£º

< %@ 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ΪÄãµÄÊý¾Ý¿âÃû

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()) {% >

ÄúµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º< %=rs.getString(1)%>

ÄúµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º< %=rs.getString(2)%>

< %}%>

< %out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");%>

< %rs.close();

stmt.close();

conn.close();

% >

< /body>

< /html>

Áù¡¢jspÁ¬½ÓMySQLÊý¾Ý¿â

testmysql.jspÈçÏ£º

< %@ 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ΪÄãµÄÊý¾Ý¿âÃû

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Á¬½ÓPostgreSQLÊý¾Ý¿â

testmysql.jspÈçÏ£º

< %@ 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ΪÄãµÄÊý¾Ý¿âÃû

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()) {% >

ÄúµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º< %=rs.getString(1)%>

ÄúµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º< %=rs.getString(2)%>

< %}%>

< %out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");%>

< %rs.close();

stmt.close();

conn.close();

% >

< /body>

< /html>
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ