jAVA问题

王朝知道·作者佚名  2009-05-04
窄屏简体版  字體: |||超大  
 
分類: 電腦/網絡 >> 程序設計 >> 其他編程語言
 
問題描述:

import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JTextField;import javax.swing.JList;import javax.swing.DefaultListModel;import javax.swing.JScrollPane;import java.awt.BorderLayout;import java.sql.DriverManager;import java.sql.Connection;import java.sql.Statement;import java.sql.ResultSet;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class KS extends JFrame implements ActionListener{private JPanel pan=new JPanel();private JTextField jtf=new JTextField();private DefaultListModel dlm=new DefaultListModel();private JList list=new JList(dlm);private JScrollPane jsp=new JScrollPane(list);private JButton but1=new JButton("获得信息");private JButton but2=new JButton("修改信息");private Connection conn;private Statement st;private ResultSet rs;public KS(){pan.add(but1);pan.add(but2);but1.addActionListener(this);but2.addActionListener(this);this.getContentPane().setLayout(new BorderLayout());this.getContentPane().add(jsp,BorderLayout.CENTER);this.getContentPane().add(pan,BorderLayout.SOUTH);this.setSize(400,300);this.setVisible(true);}public static void main(String [] args){JFrame.setDefaultLookAndFeelDecorated(true);new KS();}public void actionPerformed(ActionEvent e){if(e.getSource()==but1){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn=DriverManager.getConnection("jdbc:odbc:Northwind");st=conn.createStatement();String str []=null;rs=st.executeQuery("select ProductName,UnitPrice from Products ");while(rs.next()){str[0]=rs.getString(1);str[1]=rs.getString(2);dlm.addElement(str[0]+":"+str[1]);}}catch (Exception ex){}}}}库是系统的Northwind 库,数据源是 Northwind里的价钱是money型的 我怎么获得出来

參考答案:

while(rs.next()){rs.getString("UnitPrice ");}

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航