小弟做的查找功能,用SYstem.out.println测试不成功!!!!  field2.getText() 是文本框架 我做删除数据这样就是对的, 可不知道做查找为什么查不出来,请个为大哥帮忙看下,怎么改才能对!!!  小弟没分了,不好意思啊....class lookup
{
public void look(String name)
{
uarsql uua = new uarsql();
try
{
PreparedStatement ppt = uua.sn.prepareStatement("select * from ta1 where name=? ");
ppt.setString(1, field2.getText());
ppt.execute();
}
catch (Exception e)
{
e.printStackTrace();
       
}

button3.addActionListener(new ActionListener()
{     public void actionPerformed(ActionEvent e) 
{
if(e.getSource()==button3)
{
String s=  JOptionPane.showInputDialog(null, "请输入要查找的姓名!");
if(s==field2.getText())
{
System.out.println("正确");
}
else
{
System.out.println("错误");
}


}


}

});


}

解决方案 »

  1.   

    PreparedStatement   ppt   =   uua.sn.prepareStatement("select   *   from   ta1   where   name=?   "); 
    ppt.setString(1,   field2.getText()); 
    ppt.execute(); 这里有问题,首先,
    uua.sn.prepareStatement-------是什么意思?
    正确的应该是一个Connection类型的对象.prepareStatement(sql);
    Connection是链接数据库的对象.你应该知道是怎么链接的哦.
    Class.forName(驱动语句);
    Connection con = DriverMange.getConnection(url,user,password);
    ppt.execute();也有错,查询应该是ppt.executeQuery();