當前位置:首頁 » 操作系統 » java讀取資料庫並顯示

java讀取資料庫並顯示

發布時間: 2023-04-30 01:33:49

A. java資料庫中讀取的數據怎樣顯示在jsp的網頁當中

Java讀取資料庫記錄,並把讀取到的數據現在是在jsp頁面需要用到一下幾種技術:

1,jdbc java連接資料庫技術

2,Tomcat 運行jsp頁面所需要的伺服器
servlet 屬於web主流在橘絕告當前要宏鏈求中,圓明不使用。也可以達到相同效果

B. java怎樣讀取oracle資料庫的信息並用表格顯示出來,顯示的那個循環不會寫。這樣寫是錯誤的

哪一頃銷行報錯?錯誤信息是什麼?

for (int col = 1; col < metaData.getColumnCount(); col++) {

應該是 <= 吧

else if (type.equals("DATETIME")

oracle中有 datetime類型嗎?用答乎槐date的吧?

else if (type.equals("INT") || type.equals("COUNTER"))

不知道你用的清友是什麼類型,一般用 number表數字。

C. java從資料庫中讀取的數據怎樣顯示在jsp的網頁當中

創建一個servlet, 在servlet中將數據保存進request。類似request.setAttribute("name", "zhangsan"); ,穗中然後將請求轉發至jsp頁面,在jsp頁面中使用el表達式${requestScope.name}或${name}就可以獲取到顯示燃攔數據。當然皮族胡,也可以使用session。

D. java查詢資料庫的數據並顯示出來

本人使用的是 Jena-2.5.7 Mysql 5.0 mysql-connector-java-3.1.10 jdk1.6.0_07
源代碼:
import java.io.*;
import java.sql.SQLException;
import com.hp.hpl.jena.db.*;
import com.hp.hpl.jena.rdf.model.*;
public class MysqlTest{

public static final String strDriver = "com.mysql.jdbc.Driver"; // path of driver class
public static final String strURL = "jdbc:mysql://localhost/ontodb"; // URL of database
public static final String strUser = "root"; // database user id
public static final String strPassWord = "4408"; // database password
public static final String strDB = "MySQL"; // database type
public static void main(String[] args){
try{
// 創建一個資料庫連接
IDBConnection conn = new DBConnection ( strURL, strUser, strPassWord, strDB );

/禪掘/ 載入資料庫驅動好襲擾類,需要處理異常
try
{
Class.forName(strDriver);
}catch(ClassNotFoundException e){
System.out.println("ClassNotFoundException, Driver is not available...");
}

// 使用數友旦據庫連接參數創建一個模型製造器
ModelMaker maker = ModelFactory.createModelRDBMaker(conn);

// 創建一個默認模型,命名為 MyOntology
Model defModel = maker.createDefaultModel();
// 准備需要存入資料庫的本體文件,建立輸入文件流
FileInputStream inputSreamfile = null;
try
{
File file = new File("D:/Person.owl");
inputSreamfile = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Ontology File is not available...");
}

InputStreamReader in = null;
try
{
in = new InputStreamReader(inputSreamfile, "UTF-8");
} catch (UnsupportedEncodingException e) {
System.out.println("Exceptions occur33...");
e.printStackTrace();
}

// 讀取文件
defModel.read(in,null);

// 關閉輸入流讀取器
try
{
in.close();
} catch (IOException e) {
System.out.println("Exceptions occurclose1...");
e.printStackTrace();
}

// 執行數據轉換,將本體數據存入資料庫
defModel.commit();

// 關閉資料庫連接
try
{
conn.close();
} catch (SQLException e) {
System.out.println("Exceptions occur22...");
e.printStackTrace();
}
}catch(RDFRDBException e){
System.out.println("Exceptions occur...");
}

}
}
輸出結果
Tue Dec 30 17:07:06 CST 2008 TRACE:
Tue Dec 30 17:07:06 CST 2008 TRACE:

.....
Tue Dec 30 17:07:06 CST 2008 TRACE:
Tue Dec 30 17:07:06 CST 2008 TRACE:

Exceptions occur...
幫忙解決一下。。。

E. 怎麼用JAVA把資料庫查詢結果顯示在網頁上

java從資料庫查詢結果顯示在網頁上,步驟燃蠢禪如下:第一步:連接資料庫,並取得皮塵查檔咐詢結果:importjava.sql.*;2.在JSP上顯示可以用EL表達式如${user.getName()},也可以用JAVA胸本,或都直接用out.print(user.getName());

F. java如何讀取資料庫中的路徑在標簽框中顯示圖片

1、從DB得到圖片路徑
2、載入圖片到 ImageIcon
3、顯示在JLabel中,setIcon(ImageIcon)

G. java查詢資料庫中的數據並顯示

這個山伍id肯哪纖定不行,("select * from xscj where ID="+id);
id放在引號外逗緩或面

H. java從資料庫中讀取的數據怎樣顯示在jsp的網頁當中

我用的SSM框架 這是java類

@Controller
@RequestMapping("/studentController")
public class StudentController {

@Autowired
private StudentServices studentServices;

public StudentServices getStudentServices() {
return studentServices;
}

public void setStudentServices(StudentServices studentServices) {
this.studentServices = studentServices;
}
@RequestMapping("showStudent")
public String showStudents(Model model,HttpServletRequest request){
String currentPage = request.getParameter("currentPage")==null?"0": request.getParameter("currentPage");
long studentCount = studentServices.getStudentCount();
int pageSum = (int) (studentCount%20 == 0?studentCount/20:studentCount/20+1);
if(Integer.parseInt(currentPage)>=0&&Integer.parseInt(currentPage)<pageSum){
List<Student> students = studentServices.queryAll(Integer.parseInt(currentPage),20,pageSum);
model.addAttribute("students", students);
request.setAttribute("studentCount", studentCount);
request.setAttribute("currentPage", currentPage);
request.setAttribute("唯尺pageSum", pageSum);
return "showInfos/showStudent";
}else{
return "errorPage/showError";
}
}
}

這是JSP
<body>
<div class="container">
<div class="指滾高row">
<div class="zeng"><span id="zeng">新增</span></div>
<div class="find">
<div id="selectDiv">
<select id="id_1" style="width:110px">
<option value="">----查詢條件----</option>
<option value="stuid">序號</option>
<option value="name">名字</option>
<option value="age">年齡</option>
<option value="address">地址</option>備歷
<option value="add_date">時間</option>
</select>
<input type="text" id="condition" />
<input type="button" value="查詢" id="select" />
</div>
</div>
<table class="table table-hover">
<tr class="thead">
<td>學生編號</td>
<td>學生姓名</td>
<td>學生性別</td>
<td>學生年齡</td>
<td>學生地址</td>
<td>學生生日</td>
<td>刪除學生</td>
<td>修改學生</td>
</tr>
<c:forEach items="${students }" var="stu">
<fmt:formatDate value="${stu.add_date }" var="bir" pattern="yyyy年MM月dd日"/>
<tr>
<td>${stu.stuid }</td>
<td>${stu.name }</td>
<td>${stu.sex }</td>
<td>${stu.age }</td>
<td>${stu.address }</td>
<td>${bir }</td>
<td><a href="${pageContext.request.contextPath}/studentController/deleteStudent?stuid=${stu.stuid }">刪除學生</a></td>
<td><a href="${pageContext.request.contextPath}/studentController/showSingle?stuid=${stu.stuid}">修改學生</a></td>
</tr>
</c:forEach>
</table>
<p>
<a href="studentController/showStudent?currentPage=0">首頁</a>
<a href="studentController/showStudent?currentPage=${currentPage-1}">上頁</a>
<a href="studentController/showStudent?currentPage=${currentPage+1}">下頁</a>
<a href="studentController/showStudent?currentPage=${pageSum-1}">末頁</a>
<span>共<< <label>${pageSum}</label> >>頁</span>
<span>當前第<a href="studentController/showStudent?currentPage=${currentPage-1}"><<</a> <label>${currentPage+1}</label>
<a href="studentController/showStudent?currentPage=${currentPage+1}">>></a>頁</span>
</p>

</div>
</div></body>

這是完成JSP展示資料庫的數據,其他的類我就不寫了。希望能幫到你

I. java中怎麼把資料庫中數據查詢出來在窗體中顯示

給你個思路,可以先將數據卜謹存放在一個集合裡面。因為集合是不必定義長度的。然後在根據集合長度來定義OBJ數組。給你貼段代碼。希望對畝弊猛你有幫助。
public static Object[][] slectAll(String SQL){
Object[][] obj2 = null;
ArrayList arr = new ArrayList();
Connection conn = DBAccess.getConn();
String sql = SQL;
try {
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();

while(rs.next()){
GoodsSell rl = new GoodsSell();
rl.setSellGoods_Id(rs.getString(1));
rl.setSellGoods_Name(rs.getString(2));
rl.setSellGoods_Price(Double.parseDouble(rs.getString(3)));
rl.setSellGoods_Time(rs.getString(4));
rl.setCustomer_Name(rs.getString(5));
rl.setSellGoods_SalesMan(rs.getString(6));
rl.setSell_PaymentWay(rs.getString(7));
rl.setSell_Remark(rs.getString(8));
arr.add(rl);
}
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
obj2 = new Object[arr.size()][8];

for(int i = 0;i<arr.size();i++){
obj2[i][0] = ((GoodsSell)arr.get(i)).getSellGoods_Id();
obj2[i][1] = ((GoodsSell)arr.get(i)).getSellGoods_Name();
obj2[i][2] = ((GoodsSell)arr.get(i)).getSellGoods_Price();
obj2[i][3] = ((GoodsSell)arr.get(i)).getSellGoods_Time();
obj2[i][4] = ((GoodsSell)arr.get(i)).getCustomer_Name();
obj2[i][5] = ((GoodsSell)arr.get(i)).getSellGoods_SalesMan();
obj2[i][6] = ((GoodsSell)arr.get(i)).getSell_PaymentWay();
obj2[i][7] = ((GoodsSell)arr.get(i)).getSell_Remark();

}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBAccess.closeConn();
}

return obj2;

} 但是現在jf.getContentPane().add(table); table報錯畫紅線!Exception in thread "main" java.lang.Error: Unresolved compilation problem:
table cannot be resolved 一般先將table放在jscrollpane裡面 然後將jscrollpane放在jpanel 裡面 最後迅橋將jpanel放在jframe。

J. 用java從串口讀取數據然後顯示在網頁上,能實現嗎

最近在做java串口通訊,主要是用個人電腦通過串口從RS485讀取數據,並通過crc循環冗餘校驗,把接收正確的數據解析,插明散入資料庫mysql,並用SSH技術激譽氏把資料庫數據以表格以及圖表形式顯示
思路:
1.為了從RS485讀取數據,由於暫時沒有硬體設備,系統是win7,故採用Virtual Serial Port Drive(VSPD)這塊虛擬串口軟體代替。並下載sscom32.exe模擬串口通信軟體。

2. 要想實現串口通信,用Java實現串口通信(windows系統下),需要用到sun提供的串javacomm20-win32.zip。其中要用到三個文件,配置如下:
comm.jar放置到 JAVA_HOME/jre/lib/ext;
win32com.dll放置到 JAVA_HOME/bin;
javax.comm.properties 兩個地方都要放
jre/lib(也就是在JAVA文件夾下的jre),JAVA_HOME/jre/lib下
這個配置在我電腦上測試成功,也許不需要這樣麻煩。注意的是,如果你使用myeclipse,因為它自帶jre,你需要在它所在的jre相應位置放dll以及properties文件。

是不是感覺這個很麻煩,還有windows的限制。後來我們下載rxtx這款開源包代替了剛才的comm。不僅windows下可以,linux下也可以。使用方法很簡單,配置如下:

RXTXcomm.jar放到JAVA_HOME/jre/lib/ext
rxtxSerial.dll放到JAVA_HOME/bin
如果你使用myeclipse工具,你需要把rxtxSerial.dll放到它自帶的jre里。

3.新建eclipse工程,添加comm.jar或者RXTXcomm.jar包。因為javacomm20-win32.zip包里有樣例SimpleRead.java,可以通過這個例子測試串口是否正確

4.接收數據正確後,根據傳送接收雙方的協議,採用CRC循環校驗,根據傳輸的一方的校驗函數判定是否是正確傳輸

5.把正確結束的數據解析,查看自己指定的通訊規則,然後解析

6.插入資料庫,jdbc插入

7.數據統計,定時統計每小時,每天,每月,每年的平均值,採用quartz服務來實現。

8.建立web工程,採用hibernate3,spring3,dwr技術把資料庫數據動態虛段顯示,圖表採用jfreechart,以及AJAX的運用

熱點內容
基本原理和從頭計演算法 發布:2024-05-20 04:50:32 瀏覽:28
配置情況指的是什麼 發布:2024-05-20 04:48:14 瀏覽:495
那個程序用來編譯源文件 發布:2024-05-20 04:46:45 瀏覽:549
小程序需要資料庫嗎 發布:2024-05-20 04:35:14 瀏覽:337
鏈接sqlserver 發布:2024-05-20 04:27:53 瀏覽:209
ftp文件伺服器擴容 發布:2024-05-20 04:22:21 瀏覽:646
linux心跳包 發布:2024-05-20 04:17:52 瀏覽:970
android打開資料庫文件 發布:2024-05-20 04:16:07 瀏覽:572
塑料解壓 發布:2024-05-20 03:50:09 瀏覽:76
python在伺服器端開發 發布:2024-05-20 03:31:17 瀏覽:66