導航:首頁 > 編程大全 > jsp網頁連接資料庫

jsp網頁連接資料庫

發布時間:2021-04-01 07:11:46

A. 怎麼用jsp連接資料庫到網頁十萬火急

這是連接access資料庫的:
<%@ page import="java.sql.*"%>
<%
String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:/jsp/tushu/inc/db.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn= DriverManager.getConnection(strurl);
Statement stmt=conn.createStatement();
%>
這是連接sql2000資料庫的:
<sql:setDataSource var="conn"
driver="com.microsoft.jdbc.sqlserver.SQLServerDriver" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=資料庫名稱" user="sa" password=""/>

運行jsp文件前先安裝這個軟體j2sdk-1_4_2_07-windows-i586-p.exe不然運行不了。

設置j2sdk環境:

變數名:java_home
變數值:D:\java\j2sdk1.4.2_07

變數名:classpath
變數值:.;%java_home%\lib

變數名:path
變數值:%java_home%\bin;

軟體:
JBuilder、eclipse、也可以用 Dreamweaver 8
有交流QQ說吧26158885

B. 如何用一張JSP頁面連接資料庫,實現查詢,修改操作

1.通過jdbc連接上資料庫,並從中獲取一個連接。(建議由一個工具類提供)
2.創建一個jsp頁面、一個servlet類和一個service業務邏輯類。
3.當點擊查詢按鈕時調用servlet並把文本框中的參數傳遞過去。
4.在servlet中獲取頁面傳遞過來的參數,並調用service中方法(此方法負責條件查詢並返回list集合)
5.servlet中把查詢集合放到request作用域並轉發到jsp頁面進行迭代,把數據取出展示即可。

C. JSP網站連接mysql資料庫

你的首頁打開的時候,沒有連資料庫嗎?
肯定有吧.
如果首頁沒有問題,那就說明連資料庫沒有問題啊..
500 是伺服器問題.

在用session的時候,如果異常了或者是用完了,注意一定要關閉..
你再試試吧.應該不會是資料庫的連接問題.

D. java 中 怎樣將JSP頁面與資料庫進行連接

這需要servlet作為中間環節,由servlet完成jsp頁面數據和資料庫數據的處理,然後再進行頁面轉向等操作

E. jsp頁面怎麼和資料庫連接

Str310

F. jsp動態網頁怎麼連接mysql資料庫

我感覺,最好不使用jsp去連接資料庫
<%@ page contentType="text/html; charset=gb2312" %>

<%@ page language="java" %>

<%@ page import="com.mysql.jdbc.Driver" %>

<%@ page import="java.sql.*" %>

<%

//驅動程序

String driverName="com.mysql.jdbc.Driver";

//資料庫用戶名

String userName="cl41";

//密碼

String userPasswd="123456";

//資料庫名

String dbName="db";

//表名

String tableName="dbtest";

//聯結字元串

String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection connection=DriverManager.getConnection(url);

Statement statement = connection.createStatement();

String sql="SELECT * FROM "+tableName;

ResultSet rs = statement.executeQuery(sql);

//獲得數據結果集合

ResultSetMetaData rmeta = rs.getMetaData();

//確定數據集的列數,亦欄位數

int numColumns=rmeta.getColumnCount();

// 輸出每一個數據值

out.print("id");

out.print("|");

out.print("num");

out.print("<br>");

while(rs.next()) {

out.print(rs.getString(1)+" ");

out.print("|");

out.print(rs.getString(2));

out.print("<br>");

}

out.print("<br>");

out.print("資料庫操作成功,恭喜你");

rs.close();

statement.close();

connection.close();

%>

G. html網頁怎麼通過jsp連接mysql資料庫,並且讀取資料庫中得數據,和寫入數據

1、導入.sql文件命令:mysql>
use
資料庫名;mysql>
source
d:/mysql.sql;
2、建立資料庫:版mysql>
create
database
庫名;
3、建立數據表:mysql>
use
庫名;mysql>
create
table
表名
(欄位名
varchar(20),
欄位名
char(1));
4、刪除數權據庫:mysql>
drop
database
庫名;
5、刪除數據表:mysql>
drop
table
表名;
6、將表中記錄清空:mysql>
delete
from
表名;
7、往表中插入記錄:mysql>
insert
into
表名
values
("hyq","m");
8、更新表中數據:mysql->
update
表名
set
欄位名1='a',欄位名2='b'
where
欄位名3='c';
9、用文本方式將數據裝入數據表中:mysql>
load
data
local
infile
"d:/mysql.txt"
into
table
表名;

H. 怎麼連接資料庫和JSP動態網頁

這個問題問的太寬泛

jdbc, hibernate都可以啊 hibernate也是封裝了jdbc的 用起來更方便點

隨便貼個jdbc連接SQL的例子吧

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網頁連接資料庫相關的資料

熱點內容
索尼克世代升級擋 瀏覽:171
佛山網路教育考什麼 瀏覽:128
優秀php代碼 瀏覽:409
gta4原版升級 瀏覽:865
iphone6死機怎麼解決 瀏覽:212
蘋果5s如何申請id賬號 瀏覽:154
win10系統搭建伺服器教程 瀏覽:776
賽唯攝像頭用什麼APP 瀏覽:660
linux創建配置文件 瀏覽:552
plc編程如何把感應改成按鈕 瀏覽:991
如何保存桌面app 瀏覽:740
wps的文件中轉在哪裡 瀏覽:944
win10與mac傳文件在哪裡 瀏覽:361
win10無法打開xls文件 瀏覽:32
谷歌play電影系統文件 瀏覽:926
iphone怎麼將app加入家庭 瀏覽:15
macbookpro文件夾在哪裡2020 瀏覽:799
微信賬號怎麼改密碼忘了怎麼辦 瀏覽:935
三星手機恢復出廠設置需要密碼 瀏覽:934
手機騰訊大文件找不到 瀏覽:673

友情鏈接