老是出现异常!//查找功能的实现if(e.getSource()==subMenu2[0]||e.getSource()==toolBarButton[0]){Stringidid=JOptionPane.showInputDialog("请输入要查找的学生学号");if(idid.tri...
老是出现异常!
//查找功能的实现
if(e.getSource()==subMenu2[0]||e.getSource()==toolBarButton[0])
{
String idid = JOptionPane.showInputDialog("请输入要查找的学生学号");
if(idid.trim()!=null)
{
String strSQL ="select * from Coolboy where id = '"+idid+"'";
try
{
//rs = st.executeQuery("select * from Coolboy where id ='2004010123'");
ResultSet rs = st.executeQuery(strSQL);
int count = 0;
while(rs.next()) //输出被查询的情况
{
id = rs.getString("id");
name = rs.getString("name");
department = rs.getString("department");
sex = rs.getString("sex");
birthday = rs.getString("birthday");
nation = rs.getString("nation");
++count;
}
if(count==0)
JOptionPane.showMessageDialog(null,"对不起,没有您要查找的学生!");
else
{
idT.setText(id);
nameT.setText(name);
sexT.setText(sex);
birthdayT.setText(birthday);
nationT.setText(nation);
departmentT.setText(department);
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"抱歉,程序出现异常!");
}
}
}
//以下是连接数据库
public void conDB()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载JDBC-ODBC驱动程序
}
catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null,"李少海提示您数据库加载失败了,呵呵!");
}
try
{
Connection con = DriverManager.getConnection("jdbc:odbc:jctx");
Statement st = con.createStatement();
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"李少海提示您数据库连接失败了,呵呵!");
}
}
//以下是关闭数据库
public void closeDB()
{
try
{
st.close();
con.close();
}
catch(SQLException e )
{
JOptionPane.showMessageDialog(null,"李少海提示您数据库关闭失败了,呵呵!");
}
}
异常是出现提示“抱歉,程序出现异常!”
数据库搭建全部没问题
恩,我去试试
展开