} public sat() {super("数据库查询"); b1=new JButton("查询"); add("Center",b1); textarea=new TextArea(); add("North",textarea); text1=new JTextField("1"); add("South",text1); ButtonListener blisten =new ButtonListener(); b1.addActionListener(blisten); setSize(200,100); setVisible(true); } class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent a) { Object as=a.getSource(); if(as==b1) sat1(); }
} public void sat1() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("driver is ok"); Connection con=DriverManager.getConnection("jdbc:odbc:sat","sa","prettyboy"); PreparedStatement stat=con.prepareStatement("select * from sat where id=?"); stat.setString(1,text1.getText()); b=text1.getText(); a=Integer.parseInt(String b); if(a>4) textarea.append("There is no the id"); else{ ResultSet rs=stat.executeQuery(); String temp="id name age sex"+"\r\n"; textarea.append(temp);
sat.java:50: 需要 ')'
a=Integer.parseInt(String b);
^
1 错误输出完成 (耗时 0 秒) - 正常终止
为什么呢??
完整代码是:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class sat extends JFrame
{ String b;
int a;
TextArea textarea;
JTextField text1;
JButton b1;
public static void main(String args[])
{sat f=new sat();
}
public sat()
{super("数据库查询");
b1=new JButton("查询");
add("Center",b1);
textarea=new TextArea();
add("North",textarea);
text1=new JTextField("1");
add("South",text1);
ButtonListener blisten =new ButtonListener();
b1.addActionListener(blisten);
setSize(200,100);
setVisible(true);
}
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent a)
{ Object as=a.getSource();
if(as==b1)
sat1();
}
}
public void sat1()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("driver is ok");
Connection con=DriverManager.getConnection("jdbc:odbc:sat","sa","prettyboy");
PreparedStatement stat=con.prepareStatement("select * from sat where id=?");
stat.setString(1,text1.getText());
b=text1.getText();
a=Integer.parseInt(String b);
if(a>4)
textarea.append("There is no the id"); else{
ResultSet rs=stat.executeQuery();
String temp="id name age sex"+"\r\n";
textarea.append(temp);
while(rs.next())
{
temp=rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+"\r\n ";
textarea.append(temp);
}
}
}catch(Exception e)
{
System.out.print("Could not execute the query!"+e);
}
}
}
大哥呀,有这样的吗
a=Integer.parseInt(b);