比如置顶为1,非置顶为0
select
*
from
(select
*
from
bbs
order
by
ctime
desc)
c
order
by
istop
desc
1.先查询出按时间倒序结果集
2.在上一个结果集中查询按置顶倒序的结果集
不是很明白你的要求。具体的 *** 作是怎样的的呢?
假设数据库中有个学生表:
001 张三 20
002 李四 21
假设按姓名搜索,输入搜索条件“张”:
情况1、根据搜索条件直接搜索数据库记录(通常都是这样搜索),那从数据库搜索出的记录就只有姓名包含“张”的记录,然后JTable中也就只展示这些记录,就无所谓置顶不置顶啦。
情况2、只是根据搜索条件在当前JTable展示的数据中搜索,代码如下:
import java.awt.BorderLayoutimport java.awt.GridLayout
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JScrollPane
import javax.swing.JTable
import javax.swing.JTextField
import javax.swing.border.EmptyBorder
import javax.swing.event.TableModelEvent
import javax.swing.event.TableModelListener
public class JTableTest extends JFrame {
private JPanel searchPanel
private JTextField numField
private JButton searchByNumButton
private JTextField nameField
private JButton searchByNameButton
private JTable table
private TestTableModel tableModel
public JTableTest() {
super("Simple JTable Test")
setSize(400, 300)
setDefaultCloseOperation(DISPOSE_ON_CLOSE)
searchPanel = new JPanel()
searchPanel.setBorder(new EmptyBorder(3, 3, 3, 3))
searchPanel.setLayout(new GridLayout(2, 3, 2, 3))
searchPanel.add(new JLabel("学号"))
numField = new JTextField(20)
searchPanel.add(numField)
searchByNumButton = new JButton("按学号搜索")
searchByNumButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
table.getSelectionModel().clearSelection()
tableModel.doSearchByNum(numField.getText())
}
})
searchPanel.add(searchByNumButton)
searchPanel.add(new JLabel("姓名"))
nameField = new JTextField(20)
searchPanel.add(nameField)
searchByNameButton = new JButton("按姓名搜索")
searchByNameButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
table.getSelectionModel().clearSelection()
tableModel.doSearchByName(nameField.getText())
}
})
searchPanel.add(searchByNameButton)
getContentPane().add(searchPanel, BorderLayout.NORTH)
tableModel = new TestTableModel()
tableModel.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
if (tableModel.getHitRowCount() > 0) {
table.setRowSelectionInterval(0, tableModel.getHitRowCount() - 1)
}
}
})
table = new JTable(tableModel)
JScrollPane jsp = new JScrollPane(table)
getContentPane().add(jsp, BorderLayout.CENTER)
}
public static void main(String[] args) {
JTableTest self = new JTableTest()
self.setVisible(true)
}
} import java.util.ArrayList
import java.util.Arrays
import java.util.List
import javax.swing.table.AbstractTableModel
public class TestTableModel extends AbstractTableModel {
private List<Student> data = Arrays.asList(new Student("001", "王二", 20), new Student("002",
"王二小", 19), new Student("003", "张三", 20), new Student("004", "张三丰", 21), new Student("005",
"李四", 21), new Student("006", "李四光", 19))
private List<Integer> searchHitRows = new ArrayList<Integer>()
@Override
public int getRowCount() {
return data.size()
}
@Override
public int getColumnCount() {
return 3
}
@Override
public String getColumnName(int column) {
if (column == 0)
return "学号"
else if (column == 1)
return "姓名"
return "年龄"
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Student student = data.get(rowIndex)
if (columnIndex == 0)
return student.getNum()
else if (columnIndex == 1)
return student.getName()
return student.getAge()
}
/** 按姓名搜索 */
public void doSearchByName(String key) {
searchHitRows.clear()
if (key == null || "".equals(key))
return
for (int i = 0 i < data.size() i++) {
Student studentI = data.get(i)
String value = studentI.getName()
if (value.indexOf(key) < 0)
continue
int j = 0
for (j = i - 1 j >= 0 j--) {
Student studentJ = data.get(j)
String valueJ = studentJ.getName()
if (valueJ.indexOf(key) >= 0)
break
}
Student temp = data.get(j + 1)
data.set(j + 1, studentI)
data.set(i, temp)
searchHitRows.add(Integer.valueOf(j + 1))
}
fireTableDataChanged()
}
/** 按学号搜索 */
public void doSearchByNum(String key) {
searchHitRows.clear()
if (key == null || "".equals(key))
return
for (int i = 0 i < data.size() i++) {
Student studentI = data.get(i)
String value = studentI.getNum()
if (value.indexOf(key) < 0)
continue
int j = 0
for (j = i - 1 j >= 0 j--) {
Student studentJ = data.get(j)
String valueJ = studentJ.getNum()
if (valueJ.indexOf(key) >= 0)
break
}
Student temp = data.get(j + 1)
data.set(j + 1, studentI)
data.set(i, temp)
searchHitRows.add(Integer.valueOf(j + 1))
}
fireTableDataChanged()
}
public void setData(List<Student> data) {
if (data == null)
throw new IllegalArgumentException("参数data不能为null。")
this.data = data
fireTableDataChanged()
}
public int getHitRowCount() {
return searchHitRows.size()
}
}
从数据库查询出记录后,转成Student对象列表调用TestTableModel的setData设置表格的数据。
1、首先需要打开arcgis,打开目录。2、其次需要在目录中找到文件夹链接。找到自己要创建数据库的位置。新建shp、shapefile。
3、最后选择点、根据提示 *** 作即可。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)