一、jsp连接Oracle8/8i/9i数据库(用thin模式)
:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import=".*"%>
<%
String result = ""; // 查询结果字符串
String sql = "select * from test"; // SQL 字符串
// 连接字符串,格式: "jdbc:数据库驱动名称:连接模式:@数据库服务器ip:端口号:数据库SID"
String url = "jdbc:oracle:thin:***@localhost:1521:orcl";
String username = "scott"; // 用户名
String password = "tiger"; //密码
// 创建oracle数据库驱动实例
("").newInstance();
// 获得与数据库的连接
Connection conn = (url, username, password);
// 创建执行语句对象
Statement stmt = ();
// 执行sql语句,返回结果集
ResultSet rs = (sql);
while ( () )
{
result += "/n 第一个字段内容:" + (1) + "<BR>";
}
(); // 关闭结果集
(); // 关闭执行语句对象
(); // 关闭与数据库的连接
%>
<HTML>
<BODY>
<%=result%>
</BODY>
</HTML>
二、jsp连接Sql
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import=".*"%>
<%
String sql = "select * from test";
// 连接字符串,格式: "jdbc:公司名称:数据库驱动名称://数据库服务器ip:端口号;DatabaseName=数据库名称"
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String username = "scott";
String password = "tiger";
("").newInstance();
Connection conn = DriverMa
JSP连接数据库 来自淘豆网www.taodocs.com转载请标明出处.