Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 为什么不能连入数据库?
wppdennis





发贴: 7
积分: 0
于 2006-05-08 10:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.net.*;
class f1 extends Frame implements ActionListener
{
Label label;
TextField text1;
TextArea text2;
Button button;
Panel panel1,panel2;
f1()
{
super("英汉小词典");
setBackground(Color.cyan);
setBounds(100,120,800,600);
setVisible(true);
text1=new TextField(15);
text2=new TextArea(5,10);
button=new Button("OK");
label=new Label("输入要查询的单词");
panel1=new Panel();
panel2=new Panel();
add(panel1,"North");add(panel2,"South");add(text2,"Center");
panel1.add(label);panel1.add(text1);
panel2.add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{
text2.setText("查询结果");
try{Do();}
catch(SQLException ee){}
}
}
public void Do() throws SQLException
{
String cname,ename;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){}
Connection con=DriverManager.getConnection("jdbc.odbc:XYZ","","");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("SELECT * FROM chaxun ");
while (rs.next())
{
ename=rs.getString("英文");
cname=rs.getString("中文");
if(ename.equals(text1.getText()))
{
text2.append('\n'+cname);
}
}

}
}
public class Data
{
public static void main(String arg[])
{
f1 f=new f1();
}
}


why edited on 2006-05-09 07:22


话题树型展开
人气 标题 作者 字数 发贴时间
9690 为什么不能连入数据库? wppdennis 1555 2006-05-08 10:22
7454 Re:为什么不能连入数据库? why 93 2006-05-09 07:23
8457 Re:为什么不能连入数据库? K_P_exciting 1745 2006-05-19 21:20

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923