我正在开发一个Jtable(jquery)项目,我需要根据我在组合框中选择的内容填充一个带有来自mysql的值的文本框。
这可能吗?或者只是可以在级联中填充组合框?
由于
答案 0 :(得分:1)
Yes it is possible.
Try this
jComboBox.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try
{
Connection con=null;
Statement st=null;
ResultSet rs=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url=null,userID=null,password=null;
String dbFileName=null;
String sql=null;
dbFileName = "C:/db.accdb";
url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};"+
"DBQ="+dbFileName+";";
Object name=jComboBox.getSelectedItem();
con=DriverManager.getConnection(url);//,"system","manager"
st=con.createStatement();
rs= st.executeQuery("select column1,column2 from Table where Name='"+name+"'");
while(rs.next())
{
jTextField4.setText(rs.getString(1));
jTextField5.setText(rs.getString(2));
}
con.close();
}
catch(Exception e)
{
System.out.println("GG"+e);
}
}
});