當前位置:首頁 » 操作系統 » jsp資料庫查詢

jsp資料庫查詢

發布時間: 2022-07-17 02:29:35

A. jsp中查詢資料庫功能

代碼並沒有結束呀,你只是寫到獲取參數了,至於 獲取到參數,是用來幹嘛的,你並沒有貼出來,所以不確定這幾個參數的作用。

B. 如何在一個jsp網頁中實現sql資料庫查詢和顯示結果

jsp頁面上提交用戶查詢數據的請求到action或者servlet,
java代碼中連接資料庫查詢出數據,返回到jsp頁面顯示。
這些例子網上很多的,
建議你去網上搜索一下JSP連接資料庫的帖子,
有很多代碼的。

C. 在JSP檢索頁面中查詢資料庫數據怎麼做

將你搜索到的數據方法域裡面,讓後再JSP 頁面通過 EL表達式獲取。

D. jsp資料庫查詢

sql = "select * from my_table where nian_fen>"+kai_shi_nian_fen +"and nian_fen<"+jie_shu_nian_fen;

你這樣試試,引號內是你要穿給sql的最終值,而顯然kai_shi_nian_fen 不是你要真正加到sql中的,你需要的是他的值,所以要放在引號外面,用加號鏈接。

E. 如何在一個jsp網頁中實現SQL資料庫查詢和顯示結果

jsp頁面上提交用戶查詢數據的請求到action或者servlet, 在java代碼中連接資料庫查詢出數據,返回到jsp頁面顯示。

這些例子網上很多的, 建議你去網上搜索一下JSP連接資料庫的帖子, 有很多代碼的。

F. 怎樣用JSP語言查詢資料庫中的數據,並可以修改

查詢什麼資料庫?

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>

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為你的資料庫的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()) {%>
您的第一個欄位內容為:<%=rs.getString(1)%>
您的第二個欄位內容為:<%=rs.getString(2)%>
<%}%>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

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為你的資料庫名
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(1)%>
您的第二個欄位內容為:<%=rs.getString(2)%>
<%}%>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

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為你的資料庫名
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(1)%>
您的第二個欄位內容為:<%=rs.getString(2)%>
<%}%>
<%out.print("資料庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

有了 這些代碼,不代表你就能連接資料庫了,你還得有相應java連接各個資料庫的.jar包加入到你的工程當中!

G. JSP中的資料庫查詢

rs = sql1.executeQuery("select * from table1 where 編號 ="+變數名);
這樣寫就可以了
如果編號是字元型那就得這樣寫
rs = sql1.executeQuery("select * from table1
where 編號 ='"+變數名+"'");

H. jsp頁面在資料庫查詢

String mysql="select * from task where 1=1";
if(request.getParameter("taskdate")!=null&&!request.getParameter("taskdate").equals(""))
{
mysql=mysql+" and taskdate="+request.getParameter("taskdate");
}
if(request.getParameter("tasktype")!=null&&!request.getParameter("tasktype").equals(""))
{
mysql=mysql+" and tasktype="+request.getParameter("tasktype");
}
if(request.getParameter("taskstate")!=null&&!request.getParameter("taskstate").equals(""))
{
mysql=mysql+" and tasktype="+request.getParameter("taskstate");
}
if(request.getParameter("station")!=null&&!request.getParameter("station").equals(""))
{
mysql=mysql+" and station="+request.getParameter("station");
}
假設你的完成日期、任務類型、任務狀態和分站分別為taskdate、tasktype、taskstate和station.
用jsp的話,應該這些就可以了。mysql就是你要的SQL語句。

熱點內容
蘋果2g和安卓哪個快 發布:2025-03-15 22:52:48 瀏覽:711
airpods怎麼連接安卓手機 發布:2025-03-15 22:47:11 瀏覽:294
安卓已經刪除的app在哪裡找 發布:2025-03-15 22:42:09 瀏覽:433
海量照片存儲 發布:2025-03-15 22:23:07 瀏覽:162
androidgif控制項 發布:2025-03-15 22:10:51 瀏覽:338
我的世界手機版非常好玩的伺服器推薦 發布:2025-03-15 22:04:48 瀏覽:178
怎樣解壓手機文件 發布:2025-03-15 22:04:47 瀏覽:525
我的世界手機基岩版怎麼做伺服器 發布:2025-03-15 22:04:11 瀏覽:100
郵件發送壓縮文件 發布:2025-03-15 22:04:06 瀏覽:820
資料庫中的數據特徵 發布:2025-03-15 21:56:20 瀏覽:29