title: runtime exception in mysql
body: <p>I have a code as shown below for data access object. On successful insertion of data in signup table,I want to extract only CustId of the signup table of that particular row. So am using UserName column to extract that particular users CustId in readCustomer() method. The program is as shown below:</p>
  
  <pre><code>public class RegisterDAO {
  
      public static int custId;
  
  
      private DataSource dataSource;
  
      public void setDataSource(DataSource dataSource) {
          this.dataSource = dataSource;
      }
  
      Connection conn = null;
      PreparedStatement ps = null;
      ResultSet rs = null;
  
      public void createCustomer(Register register) {
  
  
          String sql = "INSERT INTO signup "
                  + "(CustId,FirstName,LastName,Address1,Address2,Country,State,City,ZipCode,UserName,EmailId,ContactNo,MobileNo,Status)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,'ONHOLD')";
  
          Connection conn = null;
  
          try {
              conn = dataSource.createConnection();
              PreparedStatement ps = conn.prepareStatement(sql);
              ps.setInt(1, register.getId());
              ps.setString(2, register.getFirstName());
              ps.setString(3, register.getLastName());
              ps.setString(4, register.getAddress1());
              ps.setString(5, register.getAddress2());
              ps.setString(6, register.getCountry());
              ps.setString(7, register.getState());
              ps.setString(8, register.getCity());
              ps.setInt(9, register.getZipCode());
              ps.setString(10, register.getUserName());
              ps.setString(11, register.getEmailId());
              ps.setString(12, register.getContactNo());
              ps.setString(13, register.getMobileNo());
  
              ps.executeUpdate();
              ps.close();
  
  
  
  
          } catch (SQLException e) {
              throw new RuntimeException(e);
  
          }
  
          catch (NullPointerException e1){
  
          }
          finally {
              if (conn != null) {
                  try {
                      conn.close();
                  } catch (SQLException e) {
                  }
              }
          }
  
      }
  
      public void readCustomer(String username) {
  
          String sql= "select * from signup where UserName= '" + username + "'";
  
          Connection conn = null;
  
          try {
  
              conn = dataSource.createConnection();
              PreparedStatement ps = conn.prepareStatement(sql);
  
              ResultSet rs = ps.executeQuery();
              if (rs.next()) {
                  custId =rs.getInt("CustId");
                  System.out.println(custId);
                   }
          }catch (SQLException e) {
              throw new RuntimeException(e);
  
          }
  
          catch (NullPointerException e1){
  
          }
          finally {
              if (conn != null) {
                  try {
                      conn.close();
                  } catch (SQLException e) {
                  }
              }
          }
  
      }
  }
  </code></pre>
  
  <p>But this code is throwing a runtime exception as:</p>
  
  <pre><code>Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'sindhura' in 'where clause'
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
  at com.mysql.jdbc.Util.getInstance(Util.java:384)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
  at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
  at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
  at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
  at com.encryption.DAO.RegisterDAO.readCustomer(RegisterDAO.java:87)
  ... 23 more
  </code></pre>
  
  <p>Doesn't where clause take Strings is what is my question and if it takes how to solve this?
  Any help is appreciated.</p>
  
  <p>This below sentence is throwing a run time exception</p>
  
  <pre><code>String sql= "select * from signup where UserName= '" + username + "'";
  </code></pre>