新手请高手帮忙看一下我这段程序哪里有问题?
三个jcmbobox,分别显示不同的数据库查询结果.
很奇怪为什么总是没有数据显示出来.
我不知道自己哪里写得有问题.eclipse没有报错.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
public class Sclass extends JPanel
{
/**
*
*/
private static final long serialVersionUID = -3750274426007017472L;
private JComboBox class1;
private JComboBox class2;
private JComboBox class3;
private int i;
public Sclass()
{
super();
class1 = new JComboBox();
class2 = new JComboBox();
class3 = new JComboBox();
Connection con = null;
Statement st = null;
ResultSet rs = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:access");
st = con.createStatement();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (SQLException e)
{
e.printStackTrace();
}
// 得到数据并加入ComboBox
try
{
rs = st.executeQuery("select FatherId, Name, Address from tree where FAtherId= i ");
if (i == 0)
{
while (rs.next())
{
class1.addItem(rs.getString(2));
}
}
if (i == 1)
{
while (rs.next())
{
class2.addItem(rs.getString(2));
}
}
if (i == 3)
{
while (rs.next())
{
class3.addItem(rs.getString(2));
}
}
}
catch (SQLException e)
{
} finally
{
try
{
rs.close();
} catch (Exception e1)
{
}
try
{
st.close();
} catch (Exception e1)
{
}
try
{
con.close();
} catch (Exception e1)
{
}
add(class1);
add(class2);
add(class3);
}
}
}