String fileName = jTable.getValueAt(jTabel.getSelectedRow(),jTabel.getSelectedColumn()).toString;//點擊時取得單元格文本
創(chuàng)新互聯(lián)公司專注于葫蘆島網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供葫蘆島營銷型網(wǎng)站建設,葫蘆島網(wǎng)站制作、葫蘆島網(wǎng)頁設計、葫蘆島網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)服務,打造葫蘆島網(wǎng)絡公司原創(chuàng)品牌,更為您提供葫蘆島網(wǎng)站排名全網(wǎng)營銷落地服務。
serchFile(fileName, path);//path ex:C:/ D:/ E:/...ext.}});jList.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
String fname = jList.getSelectedValue().toString();//得到某個文件
/*如果要用MSOffice打開文件可用
Runtime rt = Runtime.getRuntime();
rt.exec(C:\Program Files\Microsoft Office\Office\Winword.exe \r
c:\filename1.doc c:\filename2.doc);*/File file = new File(fname);
Scanner in = new Scanner(new FileInputStream(file));
if(in.hasNextLine()){
textArea.append(in.nextLine);//在textArea對象中顯示文件內(nèi)容}}});//搜索方法public void serchFile(String fname,String fpath){
jsp搜索只支持當前頁面搜索如存在翻頁功能請使用java
以頁面列表為例:
1.在列表頁單條記錄外套一層div;div name="searchName" search="J2聯(lián)賽北九州金澤塞維"/div
search為自定義屬性 value為可搜索的關鍵字
2.js
$("[name='searchName']").each(function(){
var n = $(this).attr("search");
if(n.indexOf(name) == -1 )
{
$(this).hide();//隱藏不存在關鍵字的列表
}
});
import?java.io.*;
public?class?FileDemo{
public?static?void?main(String[]?args)throws?Exception{
//第一個參數(shù)是文件路徑,第二個參數(shù)是要搜索的文件擴展名
getFile("D:\\JavaDemo",".txt");
}
private?static?void?getFile(String?pathName,?final?String?endsWith)throws?Exception{
File?file?=?new?File(pathName);
if(!file.exists())
throw?new?RuntimeException("文件不存在,你檢索個P呀。");
file.listFiles(new?FileFilter(){
public?boolean?accept(File?file){
if(file.getName().endsWith(endsWith)){
System.out.println(file.getName());
return?true;
}else
return?false;
}
});
}
}
package com.cn.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
//import java.awt.List;
public class Query {
public ListUserVo showUser(){
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
ListUserVo list=new ArrayListUserVo();
try{
conn=JDBC_Connection.getConnection();
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from users");
while(rs.next()){
UserVo userVo=new UserVo();
userVo.setId(rs.getInt("id"));
userVo.setName(rs.getString("name"));
userVo.setAge(rs.getInt("age"));
userVo.setTel(rs.getString("tel"));
userVo.setAddress(rs.getString("address"));
list.add(userVo);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
JDBC_Connection.free(rs, conn, stmt);
}
return list;
}
public static void main(String[] args) {
Query query=new Query();
ListUserVo list=query.showUser();
if(list!=null){
System.out.print("id\t");
System.out.print("name\t");
System.out.print("age\t");
System.out.print("tel\t");
System.out.print("address\t");
System.out.println();
for(int i=0;ilist.size();i++){
System.out.print(list.get(i).getId()+"\t");
System.out.print(list.get(i).getName()+"\t");
System.out.print(list.get(i).getAge()+"\t");
System.out.print(list.get(i).getTel()+"\t ");
System.out.print(list.get(i).getAddress()+"\t");
System.out.println();
}
}
}
}
要自己加驅(qū)動,,,,這個你應該可以看懂吧,,
java編寫的GUI 怎么實現(xiàn)查找功能:
package communitys.Connect;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class dxdsy extends JFrame implements ActionListener{
private JButton button = new JButton("搜索");
private JTextField textfile = new JPasswordField("請輸入文件名稱······");
public dxdsy()
{
this.setLayout(null);
this.setBounds(200,200, 500,500);
textfile.setBounds(1, 1, 100,20);
button.setBounds(1, 25, 80,80);
this.add(button);
this.add(textfile);
button.addActionListener(this);//添加事件監(jiān)聽
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent e) {
String sql = "select * from tablename where 條件 like '%"+textfile.getText()+"%'";
try {
Class.forName("驅(qū)動字符");
Connection conn = DriverManager.getConnection("驅(qū)動字符");
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery(sql);
//這個rs集合當中就是想要的數(shù)據(jù)
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}