java语言基础代码字典 java字典用法( 四 )


popup.add(new
AbstractAction("剪切",new ImageIcon("cut.gif"))
{
public void actionPerformed(ActionEvent event)
{
text2.cut();
}
});
popup.add(new
AbstractAction("复制",new ImageIcon("copy.gif"))
{
public void actionPerformed(ActionEvent event)
{
text2.copy();
}
});
popup.add(new
AbstractAction("粘贴",new ImageIcon("paste.gif"))
{
public void actionPerformed(ActionEvent event)
{
text2.paste();
}
});
text1.setComponentPopupMenu(popup);
}
public static final int DEFAULT_WIDTH = 400;
public static final int DEFAULT_HEIGHT = 250;
private JPanel panel;
private JMenuBar menubar;
private JToolBar toolbar;
private JLabel label;
private JTextField text1;
private JTextArea text2;
private JButton selectButton;
private JButton addButton;
private JButton updateButton;
private JButton deleteButton;
private JButton soundButton;
private JButton dateButton;
private JMenuItem aboutItem;
private Connection con;
private String url;
private Statement s;
private ResultSet rs;
public BufferedWriter Buffer;
private JFileChooser chooser;
private File f;
private JFrame frame;
private int flag;
private boolean b1;
private String strsound;
}
//查询类
class select {
private Connection con;
private String url;
private PreparedStatement pstmt;
private String sql,zz;
private ResultSet rs;
select() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
url = "jdbc:odbc:test";
}
public String jselect(String str) {
try {
con = DriverManager.getConnection(url);
sql = "select 词语解释 from 字典 where 单词=?";
pstmt= con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1,str);
rs = pstmt.executeQuery();
while (rs.next()) {
System.out.print(rs.getString(1));
zz=rs.getString(1);
System.out.println(" ");
}
rs.close();
pstmt.close();
con.close();
} catch (SQLException ce) {
System.out.println(ce);}
return zz;
}
}
//增加类
class add {
private Connection con;
private String url;
private PreparedStatement pstmt;
private String sql,sql1,zz;
private ResultSet rs;
add() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
url = "jdbc:odbc:test";
}
public String jadd(String str1,String str2) {
try {
con = DriverManager.getConnection(url);
sql = "insert into 字典 values(?,?)";
pstmt= con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1,str1);
pstmt.setString(2,str2);
pstmt.executeUpdate();
Statement s = con.createStatement();
sql1 = "SELECT * FROM 字典 ";
rs = s.executeQuery(sql1);
while (rs.next()) {
System.out.print(rs.getString(1));
System.out.print(rs.getString(2));
System.out.println(" ");
}
rs.close();
pstmt.close();
con.close();
} catch (SQLException ce) {
System.out.println(ce);}
return zz;
}
}
//修改类
class update {
private Connection con;
private String url;
private PreparedStatement pstmt;
private String sql,sql1,zz;
private ResultSet rs;
update() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);

推荐阅读