新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java实现搜索功能代码 java实现搜索功能代码

java如何实现文件搜索功能

String fileName = jTable.getValueAt(jTabel.getSelectedRow(),jTabel.getSelectedColumn()).toString;//点击时取得单元格文本

创新互联公司专注于葫芦岛网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供葫芦岛营销型网站建设,葫芦岛网站制作、葫芦岛网页设计、葫芦岛网站官网定制、重庆小程序开发服务,打造葫芦岛网络公司原创品牌,更为您提供葫芦岛网站排名全网营销落地服务。

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对象中显示文件内容}}});//搜索方法public void serchFile(String fname,String fpath){

jsp页面的搜索功能怎样实现(java也可以)要代码的

jsp搜索只支持当前页面搜索如存在翻页功能请使用java

以页面列表为例:

1.在列表页单条记录外套一层div;div name="searchName" search="J2联赛北九州金泽塞维"/div

search为自定义属性 value为可搜索的关键字

2.js

$("[name='searchName']").each(function(){

var n = $(this).attr("search");

if(n.indexOf(name) == -1 )

{

$(this).hide();//隐藏不存在关键字的列表

}

});

java如何实现搜索功能。比如,输入txt就能搜索出这个文件夹内所有txt格式的文件。请给完整代码。

import java.io.*;

public class FileDemo{

public static void main(String[] args)throws Exception{

//第一个参数是文件路径,第二个参数是要搜索的文件扩展名

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;

}

});

}

}

求用java实现索引查找的代码。

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();

}

}

}

}

要自己加驱动,,,,这个你应该可以看懂吧,,

java编写的GUI 怎么实现查找功能(使用搜索

java编写的GUI 怎么实现查找功能:

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);//添加事件监听

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("驱动字符");

Connection conn = DriverManager.getConnection("驱动字符");

Statement sta = conn.createStatement();

ResultSet rs = sta.executeQuery(sql);

//这个rs集合当中就是想要的数据

} catch (ClassNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (SQLException e2) {

// TODO Auto-generated catch block

e2.printStackTrace();

}

}

}


新闻名称:java实现搜索功能代码 java实现搜索功能代码
网站地址:http://www.wjwzjz.com/article/hpeccc.html
在线咨询
服务热线
服务热线:028-86922220
TOP