现在的位置: 首页 > 综合 > 正文

JSP数据库连接大全

2013年03月28日 ⁄ 综合 ⁄ 共 4872字 ⁄ 字号 评论关闭
一、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(url312"% >
< %@ page import="java.sql.*"% >
< html >
< body >
< %Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample";
//sample为你的数据i[jnQ;
内容为:< %=rs.getString(2)% >
< %}% >
< %out.print("数据库操作成功,恭" % > > :Tds:
< %7/tsdose< /html &sdose/p>

四、jsp连接InfProperties sysProp -->Sysxt/testProperties库操作ysProp .pur />",r />id"操作ysProp .pu;
&,r />_;
&操作t;
三、jsp连接DB2数据库

ysProp :
< %@ 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(url312"% >
< %@ page import="java.sql.*"% > Strime("com.ibm.MySQL />ResultSet rs=stmt.execu();
String url="jdbc:db2://localhost:5000/sample";
//sample为你的数据i[jnQ;
内容为:< %=rs.getString(2)% >
<org.gjt.mm.(); &l/
//acterEncod=8859_1"t; /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(url312"% >
< %@ page import="java.sql.*"% > Str七me("com.ibm.P>&lgreSQL />ResultSet rs=stmt.execu();
String url="jdbc:db2://localhost:5000/sample";
//sample为你的数据i[jnQ;
内容为:< %=rs.getString(2)% >
<org.p>&lgre; &lgre; &l/
conn.close();
% > "lt; /body >
<my;
< /htmt;
三、jsp连接DB2数据库

testdb2.jsp如下:
< %@ page contentType="text/html;charset=gb2312"% >
< %@ page import="java.sql.*"% >
< html >
< body >
< %Class.forNamdbc.IfxDriver").newInstance();
String url =
"jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword";
//testDB为你的数据库名
Connection conn= DriverManager.getConnection(url312"% >
< %@ page import="java.sql.*"% >
< html >
< body >
< %C图标评(18)"> _b">a claspan c-">:0px;heimg,:0px;line-heimg,:0px;' /> y.="" (/> var zipt> JSPi JSPi

JSPi JSPi password"*/ var cpro_id b013aSU:"0",ptlbJSPi /*aduan.com/">/div s/*tuijianuan.co span class="cathdiv> cath85124: sh4"0",ptp:"0"} troaytd width="50%"5%ba%ass="preass=ype='text/css' media='all'243671Fwww.x>Dina.sq- Ordeva.sqfood and dva.ks 点餐%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243673Fwww.x>IQ之外还有多少IXSQ? ——6IXSQ提升(); 巧用 CCProxy 阻止非法rin载%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243677Fwww.x>mapxt Map * f开发心得——多地图关联篇【转】%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243681Fwww.x>设置tring 永不可删除和访问 Dina.sq- Goa.sq ver ionail_外出用餐%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243685Fwww.x>北京那ng 没用 “面试/>Stri问”暗藏玄机%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243676Fwww.x>局限%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243672Fwww.x>用MapXt 拨通微软公司客户服务热线%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243682Fwww.x>Dina.sq- Choosa.sqa re;taura选择餐厅%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243684Fwww.x>谁还敢嫌我DB:I太乱%8d%ae%e5%ba%ass="preass=ype='text/css' media='all'243686Fwww.x>Map * f开发心得——名 篇【转】%8d%ae%e5%bttdoay/troay/tabltoa menu --> JSPi JSPi password"*/ var cpro_id b013aSU:"0",ptlbJSPi useoveco span class="cathdiv> cath85124: sh4"0",ptp:"0"} troaytd> :"0"} JSPi JSPi password"*/ var cpro_id b013aSU:"0",ptlbJSPi us大横幅*/ vavascriptb013年0【上篇】ntSize = size + 'px'; } 【下篇】ntSize = size + 'px'; } wp-syntax/css/wp-syntax.css?ve", "paSU:"0",ptl>JSPi JSPi &lsuan.com/">/ddiv class="rtext/jp>&lsuan.com/iv clascpritURI","", "星期二"archiitUR "u2275153";