三jsp連接DB數據庫
testdbjsp如下
<%@ page contentType=
text/html;charset=gb
%>
<%@ page import=
java
sql
*
%>
<html>
<body>
<%Class
forName(
com
ibm
db
jdbc
app
DB
Driver
)
newInstance();
String url=
jdbc:db
://localhost:
/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(
)%>
您的第二個字段內容為
<%=rs
getString(
)%>
<%}%>
<%out
print(
數據庫操作成功
恭喜你
);%>
<%rs
close();
stmt
close();
conn
close();
%>
</body>
</html>
四jsp連接Informix數據庫
testinformixjsp如下
<%@ page contentType=
text/html;charset=gb
%>
<%@ page import=
java
sql
*
%>
<html>
<body>
<%Class
forName(
com
informix
jdbc
IfxDriver
)
newInstance();
String url =
jdbc:informix
sqli://
:
/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(
)%>
您的第二個字段內容為
<%=rs
getString(
)%>
<%}%>
<%out
print(
數據庫操作成功
恭喜你
);%>
<%rs
close();
stmt
close();
conn
close();
%>
</body>
</html>
[] [] []
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20743.html