java - What is the logic of creating the Mysql SELECT Statement for drop down in Struts + JSP? -


can please me rectify code below, i'm trying create populated drop down list in struts 2 in eclipse ide. first time use 'struts' 'ide eclipse'. specific select statement not know how write code that, when user selects 'make' of car, database extracts different 'models' of make. other select items 'color', should optional in user can proceed search 'make' minus choosing option them. please i'm new in actionclass , database. thanx in advance.

package drive;  import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.resultset;  import com.opensymphony.xwork2.actionsupport;  public class carsearch extends actionsupport {  private string model; private string modification; private string engine; private string color; private string bodytype; private string minprice; private string maxprice; private string mileage; private int minyear; private int maxyear; private string make;  public string execute () {     string ret = none;     connection conn = null;      try {         string url = "jdbc:mysql://localhost/cars";         class.forname("com.mysql.jdbc.driver");         conn = drivermanager.getconnection(url, "root", "$jademedia247");         string sql = "select make type where";         sql+=" model = ? , modification = ? ";         preparedstatement ps = conn.preparestatement (sql);         ps.setstring(1, model);         ps.setstring(2, modification);         resultset rs = ps.executequery();          while (rs.next()){             make = rs.getstring(1);             ret = success;         }     } catch (exception e) {         ret = error;     } {          if (conn != null) {             try {                 conn.close();             } catch (exception e) {             }         }     }     return ret; }  public string getmodel() {     return model; }  public void setmodel(string model) {     this.model = model; }  public string getmodification() {     return modification; }  public void setmodification (string modification) {      this.modification = modification; }  public string getengine() {     return engine; }  public void setengine (string engine) {     this.engine = engine; }  public string getcolor() {     return color; }  public void setcolor (string color) {     this.color = color; }  public string getbodytype() {     return bodytype; }  public void setbodytype(string bodytype) {     this.bodytype = bodytype; }  public string getminprice() {     return minprice; }  public void setminprice(string minprice) {     this.minprice = minprice; }  public string getmaxprice () {     return maxprice; }  public void setmaxprice (string maxprice) {     this.maxprice = maxprice;  }   public string getmileage () {     return mileage; }  public void setmileage (string mileage) {     this.mileage = mileage ; }  public int getminyear() {     return minyear; } public void setminyear(int minyear) {     this.minyear = minyear; }  public int getmaxyear() {     return maxyear; } public void setmaxyear(int maxyear) {     this.maxyear = maxyear; }  public string getmake() { return make; } public void setmake(string make){     this.make = make; } } 

    preparedstatement ps = conn.preparestatement ("select field_name table_name model = ? , modification = ? ");     ps.setstring(1, model);     ps.setstring(2, modification);         resultset rs = ps.executequery();  

//it


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -