|
亲,只有注册或登录才能下载更有用的哦
您需要 登录 才可以下载或查看,没有账号?注册
×
(转载)利用Java访问SQL Server2000数据库<br>
<br>
<A HREF="http://www.now.net.cn/host" TARGET=_blank><IMG onmouseover="javascript:if(this.width>520)this.width=520;" src="http://b.todayisp.com/ad580x60_h.gif" onload="javascript:if(this.width>520)this.width=520;" align=absmiddle border=0></A><br><br>运行程序等其他技术问题,请看这里 : <a target=_blank href="http://www.now.net.cn/support/">http://www.now.net.cn/support/</a> <br><br>将代码保存在jdbc.java文件中 <br><br>import java.awt.*;import java.awt.event.*;import java.sql.*; <br>public class jdbc //定义主类 <br>{public static void main(String args[]) <br>{GUI gui=new GUI(); //创建类GUI的对象 <br>gui.pack(); //装载执行GUI类 <br>} <br>} <br>class GUI extends Frame implements Action Listener <br>{ TextArea text; Panel panel; TextField sno; Button btn; <br>GUI() //构造方法 <br>{ super("物资情况查询");setLayout(new BorderLayout()); <br>setBackground(Color.cyan); <br>setVisible(true);text=new TextArea(); <br>btn=new Button("查询"); sno=new TextField(16); <br>panel=new Panel(); <br>panel.add(new Label("输入被查询的物资编号:")); <br>panel.add(sno); panel.add(btn); <br>add("North",panel); add(text,"Center"); <br>text.setEditable(false);btn.addActionListener(this); <br>addWindowListener(new WindowAdapter() <br>{ public void windowClosing(WindowEvent e) <br>{ setVisible(false); System.exit(0); <br>} <br>}); <br>} <br>public void actionPerformed(ActionEvent e) { <br>if(e.getSource()==btn) //当用户按下查询按钮时 <br>{ text.setText("查询结果“+”\n’); //显示提示信息 <br>try <br>{ Liststudent(); } <br>catch(SQLException ee) { } <br>} <br>} <br>public void Liststudent() throws SQLException //针对数据库的操作 <br>{ String bh,mc,xh,lb,dw,sj; <br>int sl; float dj,je; <br>try <br>{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } <br>catch(ClassNotFoundException e) { } <br>Connection con=DriverManager.getConnection("jdbc:odbc:wzgl"); <br>Statement sql=con.createStatement(); //创建Statement对象 <br>ResultSet rs=sql.executeQuery("select * from wuzi"); <br>while(rs.next()) //输出被查询的情况 <br>{ bh=rs.getString("物资编号");mc=rs.getString("物资名称"); <br>xh=rs.getString("规格型号");lb=rs.getString("类别"); <br>dw=rs.getString("计量单位");sl=rs.getInt("数量"); <br>dj=rs.getFloat("单价"); je=rs.getFloat("金额"); <br>sj=rs.getDate("时间").toString(); <br>if(bh.trim().equals(sno.getText().trim())) <br>{text.append(\n+"物资编号"+" "+"物资名称"+" "+"规格型号"+" "+"类别"+" "+"计量单位"+" "+"数量"+" "+"单价"+" "+"金额"+" "+"时间"+\n); <br>text.append(\n+bh+" "+mc+" "+xh+" "+lb+" "+dw+" "+sl+" "+dj+" "+je+" "+sj+" "+\n); } <br>} <br>} <br>} <br><br><br>----------------------------------------------------------------------------------- <br>哪位需要域名注册,虚拟主机 支持 asp asp.net java php的都有! Q我了:168075865 ~~ <br>
<br>有新款虚拟主机呀----<a target=_blank href="http://www.now.net.cn/host">http://www.now.net.cn/host</a><br>
|
|