三个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);
}
}
}
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);
}
}
}
解决方案 »
- MyEclipse 6 java中文开发教程
- 各位老牛请进来喝杯茶,j2EE应该怎么学?学习方法是什么?
- 关于String传址还是传值
- 急!求助!Hibernate中遇到Could not synchronize database state with session问题
- JBuilder中有没有那种可以多选的下拉列表框
- 初学java,有一作业,请大侠们帮忙了(高分)。
- ???在java怎样声明、创建象C语言中的结构体(struct)变量???在线等待
- 有关SCJP的问题(广泛收集!有价值的都给分) 谢谢大家!
- 我想在URL里传一个对象过去,有没有什么好方法?
- 菜鸟求救!哪位大虾有关于javaApplet实现简单计算器的代码!在线等候!
- 在java的函数中用 synchronized限定的函数与能够保证该函数内的多个sql完整执行
- JFilechoose问题
还有
rs = st.executeQuery("select FatherId, Name, Address from tree where FAtherId= i ");
这一句应该是:
rs = st.executeQuery("select FatherId, Name, Address from tree where FAtherId="+ i );