現在有好多初學jsp的網友經常會問數據庫怎麼連接啊
一
testoracle
<%@ page contentType="text/html;charset=gb
<%@ page import="java
<html>
<body>
<%Class
String url="jdbc:oracle:thin:@localhost:
//orcl為你的數據庫的SID
String user="scott";
String password="tiger";
Connection conn= DriverManager
Statement stmt=conn
String sql="select * from test";
ResultSet rs=stmt
while(rs
您的第一個字段內容為
您的第二個字段內容為
<%}%>
<%out
<%rs
stmt
conn
%>
</body>
</html>
二
testsqlserver
<%@ page contentType="text/html;charset=gb
<%@ page import="java
<html>
<body>
<%Class
String url="jdbc:microsoft:sqlserver://localhost:
//pubs為你的數據庫的
String user="sa";
String password="";
Connection conn= DriverManager
Statement stmt=conn
String sql="select * from test";
ResultSet rs=stmt
while(rs
您的第一個字段內容為
您的第二個字段內容為
<%}%>
<%out
<%rs
stmt
conn
%>
</body>
</html>
三
testdb
<%@ page contentType="text/html;charset=gb
<%@ page import="java
<html>
<body>
<%Class
String url="jdbc:db
//sample為你的數據庫名
String user="admin";
String password="";
Connection conn= DriverManager
Statement stmt=conn
ResultSet
String sql="select * from test";
ResultSet rs=stmt
while(rs
您的第一個字段內容為
您的第二個字段內容為
<%}%>
<%out
<%rs
stmt
conn
%>
</body>
</html>
四
testinformix
<%@ page contentType="text/html;charset=gb
<%@ page import="java
<html>
<body>
<%Class
String url =
"jdbc:informix
user=testuser;password=testpassword";
//testDB為你的數據庫名
Connection conn= DriverManager
Statement stmt=conn
String sql="select * from test";
ResultSet rs=stmt
while(rs
您的第一個字段內容為
您的第二個字段內容為
<%}%>
<%out
<%rs
stmt
conn
%>
</body>
</html>
五
<%@page import="java
import ="java
import ="java
import="java
contentType="text/html; charset=gb
buffer="
%><%! int all
String odbcQuery;
Connection odbcconn;
Statement odbcstmt;
ResultSet odbcrs;
String username
String datetime;
%>
<%
try{
Class
}catch (ClassNotFoundException e)
{ out
}
try{
odbcconn = DriverManager
odbcstmt = odbcconn
odbcQuery="Select * From book where datetime>
odbcrs=odbcstmt
int i=
while (i<
while (odbcrs
{
//*/////////////////////////顯示數據庫的內容用於調試程序是用//
int ii;
try{
try{
for (ii=
out
}catch (NullPointerException e) {
out
}
}catch (SQLException e){
}
}
odbcrs
odbcstmt
odbcconn
}catch (SQLException e)
{ out
}
%>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19748.html