lz ?你好
創(chuàng)新互聯(lián)憑借在網(wǎng)站建設(shè)、網(wǎng)站推廣領(lǐng)域領(lǐng)先的技術(shù)能力和多年的行業(yè)經(jīng)驗(yàn),為客戶提供超值的營銷型網(wǎng)站建設(shè)服務(wù),我們始終認(rèn)為:好的營銷型網(wǎng)站就是好的業(yè)務(wù)員。我們已成功為企業(yè)單位、個(gè)人等客戶提供了做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)服務(wù),以良好的商業(yè)信譽(yù),完善的服務(wù)及深厚的技術(shù)力量處于同行領(lǐng)先地位。
代碼還是比較簡單 ?就是需要一個(gè)做好的txt英漢詞典文檔
以下是一個(gè)簡單的例子:
import?java.awt.*;
import?javax.swing.*;
import?java.awt.event.*;
import?java.io.*;
import?java.util.*;
public?class?EC_Dictionary?extends?JFrame{
private?JTextField?input;
private?JButton?search;
private?JTextArea?output;
public?EC_Dictionary(){
super("英漢詞典");
input?=?new?JTextField(14);
search?=?new?JButton("查詢");
search.setFont(new?Font("宋體",?Font.PLAIN,?15));
search.addActionListener(new?ActionListener(){
public?void?actionPerformed(ActionEvent?e){
searchWords();
}
});
output?=?new?JTextArea(10,18);
output.setEditable(false);
output.setFont(new?Font("宋體",?Font.PLAIN,?18));
output.setForeground(Color.RED);
setLayout(new?FlowLayout(FlowLayout.CENTER,?5,?20));
getContentPane().add(input);
getContentPane().add(search);
getContentPane().add(output);
setSize(300,320);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(3);
setVisible(true);
}
//查詢單詞
public?void?searchWords(){
try?{
BufferedReader?br?=?new?BufferedReader(new?FileReader("dictionary.txt"));
String?line,?inputWord;
boolean?isFound?=?false;
inputWord?=?input.getText();
if(inputWord.equals("")){
return;
}
while((line?=?br.readLine())?!=?null){
Scanner?in?=?new?Scanner(line);
if(in.next().equals(inputWord)){
int?offset?=?inputWord.length();
output.setText("\n\n\n\n"+line.substring(offset));
isFound?=?true;
break;
}
}
if(!isFound){
output.setText("沒找到相應(yīng)項(xiàng)..");
}
}
catch?(Exception?ex)?{
ex.printStackTrace();
}
}
public?static?void?main?(String[]?args)?{
new?EC_Dictionary();
}
}
運(yùn)行效果:
ps:
本程序要用附件中dictionary.txt文檔 ?lz要把源程序和這個(gè)文檔放在同目錄下 ?才能正常運(yùn)行
希望能幫助你哈
說先說:你的代碼有錯(cuò)誤,在最下面,我已經(jīng)該過了,不是大問題。
如果你想學(xué)好java的話,可以根據(jù)這個(gè)代碼加上我的注解去理解,但不要學(xué)這個(gè)代碼的變成方式或者說變成習(xí)慣,這個(gè)代碼基本上無誤,但犯了一些常識性問題,如果養(yǎng)成了這些不好的習(xí)慣對以后的編程會(huì)有壞的影響。
我是英文學(xué)的java,所以有些注解可能不通順,但我盡力而為了。 有的注解有點(diǎn)長,所以你復(fù)制到編譯器后稍微編輯一下就可以運(yùn)行。代碼是可以運(yùn)行,沒有問題的。
------------------------------------
import javax.swing.*; //用來創(chuàng)建圖形界面,如窗口,表格,按鈕等。
import java.awt.*; //作用同上,但已經(jīng)很少用,能用swing的地方就不要用awt
import java.awt.event.*;//事件管理和控制
import java.sql.*; //數(shù)據(jù)庫語句和操作
import java.lang.System;//這個(gè)不知道
/*下面的這6個(gè)沒有用,純屬寫出來嚇人*/
import javax.swing.tree.*;
import javax.swing.event.*;
import java.util.*;
import javax.swing.border.*;
import javax.swing.table.*;
import java.lang.String.*;
class Mywindow extends JFrame implements ActionListener//這個(gè)類implements actionlistener,意思就是它自己就可以執(zhí)行actionListener的任務(wù)
{
JTextField txf=new JTextField(20); //建一個(gè)文字編輯框,長度20(只可以輸入一行文字)
JTextArea jt=new JTextArea(10,30);//建一個(gè)文字編輯區(qū)域,長10寬30(可以回車然后輸入多行文字)
JButton btn1=new JButton("查詢");//建一個(gè) 查詢 按鈕
Mywindow()//構(gòu)造函數(shù),每個(gè)類必有的,可以為空
{
JFrame frm=new JFrame("Search");//建一個(gè)窗口(讓其他的東西有地方可放,和容器一樣。是3個(gè)最高級別的容器之一,其他兩個(gè)是applet和window)
frm.setBounds(400,300,450,350);//設(shè)置大小和位置,前兩個(gè)是坐標(biāo),后兩個(gè)是大小
Container con=getContentPane();//建一個(gè)awt容器對象,用來添加其他元素,最好用這個(gè)添加元素。像:frm.add(all); 可以寫成 con.add(all);
JPanel pnl4=new JPanel();//建一個(gè)面板用來添加其他元素(第二級別容器,最后需要被添加在frame上)
pnl4.setBorder(BorderFactory.createTitledBorder("Search"));//設(shè)置邊框樣式
pnl4.add(txf);//把文字編輯框添加到面板上
pnl4.add(btn1);//把按鈕添加到面板上
btn1.addActionListener(this);//添加事件行為監(jiān)聽器(this),this意思是當(dāng)前對象,呼應(yīng) implements ActionListener
JPanel pnl5=new JPanel();//同上
pnl5.setBorder(BorderFactory.createTitledBorder("Result"));//同上
jt.setWrapStyleWord(true);//這個(gè)忘了
jt.setLineWrap(true);//在區(qū)域規(guī)定的寬度下,如果文字的輸入到一行最后則會(huì)自動(dòng)令其一行繼續(xù),如果是(false),文字輸入就會(huì)在這一行繼續(xù)知道回車
pnl5.add(new JScrollPane(jt));//個(gè)這個(gè)面板添加右側(cè)滾動(dòng)條,當(dāng)文字輸入超過 長* 寬后 滾動(dòng)條出現(xiàn)
JPanel all=new JPanel();//同上
all.setLayout(new BorderLayout());//設(shè)置布局,borderlayout()分東西南北(上下左右)中五個(gè)部分 無論窗口多大,中間占得面積最大
all.add(pnl4,BorderLayout.NORTH);//添加一個(gè)面板在上面
all.add(pnl5,BorderLayout.CENTER);//添加一個(gè)在中間
frm.add(all);//把最大的這個(gè)面板添加到窗口上 也可以用con.add(all);
frm.setVisible(true);//設(shè)置窗口顯示屬性 如果false就是不顯示
frm.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});//加一個(gè)窗口監(jiān)聽 如果點(diǎn)小紅叉關(guān)閉窗口則系統(tǒng)推出
}
public void actionPerformed(ActionEvent e)//作為ActionListener類的構(gòu)造函數(shù),如果你的class implements ActionListenser, 那就必須得有這個(gè),也可以單獨(dú)寫一個(gè)class,不過有點(diǎn)麻煩
{
if(e.getSource()==btn1)//當(dāng)按鈕被點(diǎn)擊的時(shí)候
{
String str="";//建一個(gè)字符串
String tmp=this.txf.getText();//同上,這個(gè)字符串的值是當(dāng)前對象(窗口)中,文本框輸入的值
for(int k=0;ktmp.length();k++)//建一個(gè) 永久循環(huán)
str+=tmp.charAt(k)+"%";//把 % 插入每一個(gè)字符后面, 作用后面說
String sql=null;//同上
Statement stmt=null;//定義一個(gè)stmt,用來建數(shù)據(jù)庫連接的
sql="select * from chinese where charsound like'"+str+"'";//創(chuàng)建一個(gè)sql數(shù)據(jù)庫語句,但它本身還是一個(gè)字符串
System.out.println(sql);//系統(tǒng)顯示創(chuàng)建的語句,通常找錯(cuò)時(shí)候用的
try{//try 和 catch 的作用一句兩句說不清楚 不知道你就自己查查
Class.forName("com.mysql.jdbc.Driver");//或者:Class.forName("org.gjt.mm.mysql.Driver");關(guān)聯(lián)mysql數(shù)據(jù)庫驅(qū)動(dòng)
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/japan?user=rootpassword=sa");//建立連接,數(shù)據(jù)庫名japan(為什么不是chinese?)用戶名root密碼sa
stmt=conn.createStatement();//建立statement對象,用來發(fā)送sql語句到數(shù)據(jù)庫
ResultSet rs=stmt.executeQuery(sql);//運(yùn)行語句并建立一個(gè)查詢結(jié)果的集合
System.out.println("\n------------------------search :"+str+"-------------------------------");//同上
jt.setText("");//清空文本編輯區(qū)域
while(rs.next())//while循環(huán),當(dāng)還有結(jié)果的時(shí)候,把所有查詢結(jié)果添加加到文本編輯區(qū)域中
{
jt.append(new String(rs.getString("charname").getBytes("iso-8859-1"),"gb2312")+"\t");
System.out.print(new String(rs.getString("charname").getBytes("iso-8859-1"),"gb2312")+"\t");
}
stmt.close();//關(guān)閉關(guān)連,很重要。
}
catch(Exception eq){System.out.println("error");}
//--------------------------------------------------------------end btn1-------
}
}
public static void main(String args[])
{
Mywindow win=new Mywindow();//建立一個(gè) mywindow 對象
win.pack();//將所有元素整合
win.show();
}
}
public class Test4 {
static MapString, String map = new TreeMapString, String();
static {
map.put("watermelon", "西瓜");
map.put("banana", "香蕉");
map.put("strawberry", "草莓");
map.put("apple", "蘋果");
}
public static void main(String[] args) {
System.out.println("請輸入單詞");
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str1 = sc.nextLine();
if(str1.equals("退出")){
return;
}
else if (map.containsKey(str1)) {
System.out.println(map.get(str1));
} else{
System.out.println("次單詞為新詞,添加意思");
Scanner sc1 = new Scanner(System.in);
String str2=sc1.nextLine();
map.put(str1, str2);
System.out.println("添加成功。");
}
}
}
}
idea中文導(dǎo)出java源代碼方法:
1、進(jìn)入idea,打開項(xiàng)目的projectstructure。
2、鼠標(biāo)右鍵項(xiàng)目名稱,選擇openmodulesettings。
3、點(diǎn)擊菜單fileprojectstructure。
4、在projectstructure中選擇artifacts,點(diǎn)擊add,選擇JARFrommoduleswithdependencies。
5、進(jìn)行相關(guān)的配置,即可導(dǎo)出java源代碼。
1. 由于你單詞本固定,無需動(dòng)態(tài)改變,用String數(shù)組就可以了,不用map也非常快了。
2. 將各個(gè)單詞提前排序,查詢時(shí)就可以用2分法,復(fù)雜度很低。
3. 自己估算一下單詞數(shù)量,決定是否一次讀入內(nèi)存。
4. 只用到數(shù)據(jù)結(jié)構(gòu)和算法方面很基礎(chǔ)的東西,沒什么特別的??赡躩ava界面編程你需要稍稍入門即可。netbeans做界面也很好用,接近于vb了。
to laogao3232:
我說的String只是指單詞(作為key),至于每個(gè)單詞的詞條另存到其他地方??梢宰屆總€(gè)單詞另帶一個(gè)“指針”指向詞條位置。當(dāng)然也可以認(rèn)為這是一個(gè)最原始的map。
package zyhz;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.io.*;
import com.sun.media.sound.*;
public class Dictionary {
public Dictionary() {
}
public static void main(String[] args)
{
dicFrame frame = new dicFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class dicFrame extends JFrame
{
public dicFrame()
{
setTitle("Dictionary");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
panel = new JPanel();
add(panel);
//菜單欄
JMenu fileMenu = new JMenu("文件");
JMenuItem ECItem = new JMenuItem("英漢字典");
ECItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
text2.setText("請?jiān)谏厦孑斎胗⑽模。。。?);
}
});
JMenuItem CEItem = new JMenuItem("漢英字典");
CEItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
text2.setText("請?jiān)谏厦孑斎胫形模。。。?);
}
});
//備份詞庫
JMenuItem BackupItem = new JMenuItem("備份詞庫");
BackupItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
url = "jdbc:odbc:test";
String fileName;
chooser = new JFileChooser();
frame = new JFrame();
chooser.setDialogTitle("備份詞庫為");
try {
flag = chooser.showSaveDialog(frame);
} catch (HeadlessException h) {
System.out.println("Save File Dialog ERROR!");
}
if (flag == JFileChooser.APPROVE_OPTION) {
f = chooser.getSelectedFile();
fileName = chooser.getName(f);
fileName = chooser.getSelectedFile().getPath();
try {
File saveFile = new File(fileName);
FileWriter fw = new FileWriter(saveFile);
try
{
con = DriverManager.getConnection(url);
s = con.createStatement();
rs = s.executeQuery("SELECT * from 字典 ");
while (rs.next()) {
String a = rs.getString("單詞");
String b = rs.getString("詞語解釋");
text2.append(a+b+"\n");
}
rs.close();
} catch (Exception ea) {
text2.setText("查詢數(shù)據(jù)失敗");
}
fw.write(text2.getText());
fw.close();
} catch (IOException ec) {
text2.setText(fileName);
}
text2.setText("詞庫備份成功!");
}
}
});
fileMenu.add(ECItem);
fileMenu.add(CEItem);
fileMenu.add(BackupItem);
fileMenu.addSeparator();
//退出監(jiān)聽器
fileMenu.add(new
AbstractAction("退出")
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
JMenu editMenu = new JMenu("編輯");
JMenuItem addItem = new JMenuItem("添加詞匯");
addItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK));
//菜單欄增加監(jiān)聽器
addItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("沒有輸入內(nèi)容!請重新增加?。?!");
else
{
String s=text1.getText().trim();
String s1=text2.getText().trim();
text2.setText(new add().jadd(text1.getText().trim(),text2.getText().trim()));
text2.append(s+"\n"+s1+";"+" "+"http://"+"該內(nèi)容已增加!??!");
}
}
});
//菜單欄修改監(jiān)聽器
JMenuItem updateItem = new JMenuItem("修改詞匯");
updateItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U,InputEvent.CTRL_MASK));
updateItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("沒輸入所要修改的內(nèi)容!請重新輸入!?。?!");
else{
String s=text1.getText().trim();
text2.setText(new update().jupdate(text1.getText().trim(),
text2.getText().trim()));
text2.append(s+" "+"http://"+"該內(nèi)容已修改!??!");
}
}
});
//菜單欄刪除監(jiān)聽器
JMenuItem deleteItem = new JMenuItem("刪除詞匯");
deleteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,InputEvent.CTRL_MASK));
deleteItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("沒輸入所要?jiǎng)h除的內(nèi)容!請重新輸入?。。?!");
else{
String s=text1.getText().trim();
text2.setText(new delete().jdelete(text1.getText().trim()));
text2.append(s+" "+"http://"+"該內(nèi)容已刪除?。?!");
}
}
});
editMenu.add(addItem);
editMenu.add(updateItem);
editMenu.add(deleteItem);
JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic('H');
aboutItem = new JMenuItem("About");
aboutItem.setMnemonic('A');
aboutItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
new guanyu();
}
});
helpMenu.add(aboutItem);
menubar = new JMenuBar();
setJMenuBar(menubar);
menubar.add(fileMenu);
menubar.add(editMenu);
menubar.add(helpMenu);
//工具欄
label = new JLabel("請輸入:");
text1= new JTextField("");
selectButton = new JButton("查詢");
//工具欄查詢監(jiān)聽器
selectButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("沒有輸入查詢內(nèi)容!請重新輸入?。?!");
else text2.setText(new select().jselect(text1.getText().trim()));
}
});
//工具欄增加監(jiān)聽器
addButton = new JButton("增加");
addButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("沒有輸入內(nèi)容!請重新增加?。?!");
else
{
String s=text1.getText().trim();
String s1=text2.getText().trim();
text2.setText(new add().jadd(text1.getText().trim(),text2.getText().trim()));
text2.append(s+"\n"+s1+";"+" "+"http://"+"該內(nèi)容已增加?。。?);
}
}
});
//工具欄修改監(jiān)聽器
updateButton = new JButton("修改");
updateButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("沒輸入所要修改的內(nèi)容!請重新輸入!?。?!");
else{
String s=text1.getText().trim();
text2.setText(new update().jupdate(text1.getText().trim(),
text2.getText().trim()));
text2.append(s+" "+"http://"+"該內(nèi)容已修改?。?!");
}
}
});
//工具欄刪除監(jiān)聽器
deleteButton = new JButton("刪除");
deleteButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("沒輸入所要?jiǎng)h除的內(nèi)容!請重新輸入?。。?!");
else{
String s=text1.getText().trim();
text2.setText(new delete().jdelete(text1.getText().trim()));
text2.append(s+" "+"http://"+"該內(nèi)容已刪除!!!");
}
}
});
soundButton = new JButton("讀音");
soundButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
JavaSoundAudioClip player;
try{
strsound = text2.getText().trim();
FileInputStream ff = new FileInputStream("sound//"+strsound+".wav");
player = new JavaSoundAudioClip(ff);
player.play();
}
catch(Exception e) {
System.out.println("error");
e.printStackTrace();
}
}
});
//萬年歷
dateButton = new JButton("萬年歷");
dateButton.addActionListener(new
AbstractAction() {
public void actionPerformed(ActionEvent event)
{
new calendar();
}
});
toolbar = new JToolBar();
add(toolbar,BorderLayout.NORTH);
toolbar.add(label);
toolbar.add(text1);
toolbar.add(selectButton);
toolbar.add(addButton);
toolbar.add(updateButton);
toolbar.add(deleteButton);
toolbar.add(soundButton);
toolbar.add(dateButton);
text2 = new JTextArea(8,40);
text2.setLineWrap(true);
JScrollPane scroll = new JScrollPane(text2);
add(scroll,BorderLayout.CENTER);
//快捷菜單 剪切,復(fù)制,粘貼
JPopupMenu popup= new JPopupMenu();
text2.setComponentPopupMenu(popup);
popup.add(new
AbstractAction("剪切",new ImageIcon("cut.gif"))
{
public void actionPerformed(ActionEvent event)
{
text2.cut();
}
});
popup.add(new
AbstractAction("復(fù)制",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);
}
url = "jdbc:odbc:test";
}
public String jupdate(String str1,String str2) {
try {
con = DriverManager.getConnection(url);
sql = "UPDATE 字典 SET 詞語解釋=? WHERE 單詞=?";
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 delete {
private Connection con;
private String url;
private PreparedStatement pstmt;
private String sql,sql1,zz;
private ResultSet rs;
delete() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
url = "jdbc:odbc:test";
}
public String jdelete(String str1) {
try {
con = DriverManager.getConnection(url);
sql = "delete 字典 WHERE 單詞=?";
pstmt= con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1,str1);
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;
}
}
還有個(gè)數(shù)據(jù)庫,如果你能留個(gè)郵箱,我把整份程序傳給你~希望能幫到你
分享題目:中英字典java源代碼,Java英文版
本文地址:http://vcdvsql.cn/article44/heogee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航、面包屑導(dǎo)航、響應(yīng)式網(wǎng)站、、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)