国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JSP > 正文

JSP連接數(shù)據(jù)庫(kù)方法大全

2024-09-05 00:20:06
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
一、jsp連接oracle8/8i/9i數(shù)據(jù)庫(kù)(用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為你的數(shù)據(jù)庫(kù)的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()) {%>
您的第一個(gè)字段內(nèi)容為:<%=rs.getstring(1)%>
您的第二個(gè)字段內(nèi)容為:<%=rs.getstring(2)%>
<%}%>
<%out.print("數(shù)據(jù)庫(kù)操作成功,恭喜你/");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

二、jsp連接sql server7.0/2000數(shù)據(jù)庫(kù)
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為你的數(shù)據(jù)庫(kù)的
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()) {%>
您的第一個(gè)字段內(nèi)容為:<%=rs.getstring(1)%>
您的第二個(gè)字段內(nèi)容為:<%=rs.getstring(2)%>
<%}%>
<%out.print("數(shù)據(jù)庫(kù)操作成功,恭喜你/");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

三、jsp連接db2數(shù)據(jù)庫(kù)
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為你的數(shù)據(jù)庫(kù)名
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()) {%>
您的第一個(gè)字段內(nèi)容為:<%=rs.getstring(1)%>
您的第二個(gè)字段內(nèi)容為:<%=rs.getstring(2)%>
<%}%>
<%out.print("數(shù)據(jù)庫(kù)操作成功,恭喜你/");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

四、jsp連接informix數(shù)據(jù)庫(kù)
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為你的數(shù)據(jù)庫(kù)名
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()) {%>
您的第一個(gè)字段內(nèi)容為:<%=rs.getstring(1)%>
您的第二個(gè)字段內(nèi)容為:<%=rs.getstring(2)%>
<%}%>
<%out.print("數(shù)據(jù)庫(kù)操作成功,恭喜你/");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

五、jsp連接sybase數(shù)據(jù)庫(kù)
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為你的數(shù)據(jù)庫(kù)名
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()) {%>
您的第一個(gè)字段內(nèi)容為:<%=rs.getstring(1)%>
您的第二個(gè)字段內(nèi)容為:<%=rs.getstring(2)%>
<%}%>
<%out.print("數(shù)據(jù)庫(kù)操作成功,恭喜你/");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

六、jsp連接mysql數(shù)據(jù)庫(kù)
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為你的數(shù)據(jù)庫(kù)名
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()) {%>
您的第一個(gè)字段內(nèi)容為:<%=rs.getstring(1)%>
您的第二個(gè)字段內(nèi)容為:<%=rs.getstring(2)%>
<%}%>
<%out.print("數(shù)據(jù)庫(kù)操作成功,恭喜你/");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

七、jsp連接postgresql數(shù)據(jù)庫(kù)
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為你的數(shù)據(jù)庫(kù)名
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()) {%>
您的第一個(gè)字段內(nèi)容為:<%=rs.getstring(1)%>
您的第二個(gè)字段內(nèi)容為:<%=rs.getstring(2)%>
<%}%>
<%out.print("數(shù)據(jù)庫(kù)操作成功,恭喜你/");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 普格县| 全椒县| 乌鲁木齐县| 梅河口市| 金堂县| 伊金霍洛旗| 城步| 平邑县| 桑日县| 武汉市| 丹东市| 海林市| 屯昌县| 兴安县| 佛冈县| 岑溪市| 津南区| 凯里市| 分宜县| 北川| 梁平县| 小金县| 滨州市| 那曲县| 淮安市| 广安市| 翁牛特旗| 花垣县| 邛崃市| 竹溪县| 嘉定区| 长海县| 神池县| 山阴县| 吐鲁番市| 石屏县| 盖州市| 嵊州市| 丁青县| 泰宁县| 府谷县|