0
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cmc;
import java.sql.*;


/**
 *
 * @author Sahil
 */
public class signup {
    String fn,ln,un,pwd,cpwd,dob,sex,email,sec,secans;
    String emp,colg,skul,relstat,fammem,fam,con,country,state,city,pin;
    Connection cn;
    Statement st;
    int i,j,k;

   public int getI() {
        return i;
    }

    

    public int getJ() {
        return j;
    }

   

    public int getK() {
        return k;
    }

    
    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getColg() {
        return colg;
    }

    public void setColg(String colg) {
        this.colg = colg;
    }

    public String getCon() {
        return con;
    }

    public void setCon(String con) {
        this.con = con;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCpwd() {
        return cpwd;
    }

    public void setCpwd(String cpwd) {
        this.cpwd = cpwd;
    }

    public String getDob() {
        return dob;
    }

    public void setDob(String dob) {
        this.dob = dob;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmp() {
        return emp;
    }

    public void setEmp(String emp) {
        this.emp = emp;
    }

    public String getFam() {
        return fam;
    }

    public void setFam(String fam) {
        this.fam = fam;
    }

    public String getFammem() {
        return fammem;
    }

    public void setFammem(String fammem) {
        this.fammem = fammem;
    }

    public String getFn() {
        return fn;
    }

    public void setFn(String fn) {
        this.fn = fn;
    }

    public String getLn() {
        return ln;
    }

    public void setLn(String ln) {
        this.ln = ln;
    }

    public String getPin() {
        return pin;
    }

    public void setPin(String pin) {
        this.pin = pin;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getRelstat() {
        return relstat;
    }

    public void setRelstat(String relstat) {
        this.relstat = relstat;
    }

    public String getSec() {
        return sec;
    }

    public void setSec(String sec) {
        this.sec = sec;
    }

    public String getSecans() {
        return secans;
    }

    public void setSecans(String secans) {
        this.secans = secans;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getSkul() {
        return skul;
    }

    public void setSkul(String skul) {
        this.skul = skul;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getUn() {
        return un;
    }

    public void setUn(String un) {
        this.un = un;
    }
    public boolean  insert()
    {
     boolean b=false; 
     if((fn!=null)&&(ln!=null)&&(un!=null)&&(pwd!=null)&&(cpwd!=null)&&(dob!=null)&&(sex!=null)&&(email!=null)&&(sec!=null)&&(secans!=null)&&(emp!=null)&&(con!=null)&&(country!=null)&&(state!=null)&&(city!=null)&&(pin!=null))
     {
     try
     { 
    Class.forName("com.mysql.jdbc.Driver");
    cn = DriverManager.getConnection("jdbc:mysql://localhost:3307/sns?user=root&password=iaminusit");
    st=cn.createStatement();
   
    int i=st.executeUpdate("insert into logdata values('"+fn+"','"+ln+"','"+un+"','"+pwd+"','"+dob+"','"+email+"','"+sec+"','"+secans+"')");
    System.out.println(i);
    
    cn = DriverManager.getConnection("jdbc:mysql://localhost:3307/sns?user=root&password=iaminusit");
    st=cn.createStatement();
     int j=st.executeUpdate("insert into contact values('"+con+"','"+country+"','"+state+"','"+city+"','"+pin+"')");
    System.out.println(j);
    
     cn = DriverManager.getConnection("jdbc:mysql://localhost:3307/sns?user=root&password=iaminusit");
    st=cn.createStatement();
     int k=st.executeUpdate("insert into personal values('"+dob+"','"+sex+"','"+emp+"','"+colg+"','"+skul+"','"+relstat+"','"+fammem+"','"+fam+"')");
    System.out.println(k);
    
    if(i==1&&j==1&&k==1)
    {
         b=true;
    }
     
     
     }
        catch(Exception e)
        {
        System.out.print(e);
        
        }
     }
    return b;
    
    
    }
    
}

This is my bean class where query is executed??
Backslashes are added automatically in database,might be a string problem....plz help

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by peter_budo
0

Nothing to be found from this code beside that you are:

  • ignoring general Java naming convention (class name signup, should be Signup)
  • using non descriptive variable names (cn, st, would be far better as connection, statement, imagine you coming back to code after few months and have to look up all parameters/fields/variables because you can't remember what their are, since you wrote them in short-hand)
  • putting business logic into data holder object (database related stuff should be in different class)
  • having lots of duplication (you need only once open connection)
  • having no closing of connection
  • not using PreparedStatement
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.