救助!java与数据库连接实例!
import java.awt.*;import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class Win1 extends JFrame implements ActionListener
{
String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectionstr="jdbc:odbc:db2";
Connection connection=null;
Statement statement=null;
ResultSet rs=null;
String sql="SELECT * FROM 110";
JLabel label;
JTextField text;
JButton button;
JTextArea area;
JPanel p;
Win1()
{
try
{
Class.forName(DBDriver);
PreparedStatement pstmt=connection.prepareStatement("SELECT * FROM 110 WHERE 药品名称=?");
pstmt.setString(1,text.getText());
pstmt.executeQuery();
}
catch(ClassNotFoundException e)
{
}
catch(SQLException el)
{
System.out.println("bvbcx bcv "+el.getMessage());
}
try
{
connection=DriverManager.getConnection(connectionstr,"","");
statement=connection.createStatement();
rs=statement.executeQuery(sql);
}
catch(SQLException ee)
{
System.out.println("bvbcx bcv "+ee.getMessage());
}
label=new JLabel("请输入药品ID");
text=new JTextField(12);
button=new JButton("确定");
area=new JTextArea();
p=new JPanel();
p.add(label);
p.add(text);
p.add(button);
area.setWrapStyleWord(false);
area.setLineWrap(true);
area.setText("药品信息:\n");
Container con=getContentPane();
con.add(p,BorderLayout.NORTH);
con.add(new JScrollPane(area),BorderLayout.CENTER);
setBounds(200,200,300,300);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{
try
{
area.append(rs.getString("药品名称")+"\n");
}
catch(SQLException ee)
{
System.out.println("bvbcx bcv "+ee.getMessage());
}
}
}
}
public class Opple_109
{
public static void main(String args[])
{
Win1 win1=new Win1();
}
}
要实现的是把ACCESS数据库里的一个表 110的一行 显示到area中 怎么实现啊 菜鸟救助!!