com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:'where子句'中的未知列'email'

时间:2018-03-29 04:45:17

标签: java mysql spring hibernate

import edu.princeton.cs.algs4.WeightedQuickUnionUF;

public class Percolation {

    private WeightedQuickUnionUF grid;
    private WeightedQuickUnionUF grid2;
    private boolean[] openSites;
    private int numOpenSites, gridLength, topIndex, bottomIndex;

   public Percolation(int n)   {   
       // create n-by-n grid, with all sites blocked
       if (n <= 0) {
           throw new IllegalArgumentException();
       }

       int numNodes = (n * n) + 2;
       grid = new WeightedQuickUnionUF(numNodes);
       grid2 = new WeightedQuickUnionUF(numNodes);
       openSites = new boolean[n * n];
       numOpenSites = 0;
       gridLength = n;
       topIndex = n * n;
       bottomIndex = n * n + 1;
   }

   public    void open(int row, int col)  {  // open site (row, col) if it is not open already 
       //check if row and col are valid 
       if (row < 1 || row > gridLength || col < 1 || col > gridLength) {
           throw new IndexOutOfBoundsException();
       }
       //if not open, then open
       if (!isOpen(row, col)) {
           openSite(row, col);
           connectTopVirtualSite(row, col);
           connectAdjacentSites(row, col);
           connectBottomVirtualSite(row, col);
           numOpenSites++;
       }
   }

   private void openSite(int row, int col) {
       int index = convertToIndex(row, col);

       //set that site to true
       openSites[index] = true;
   }

   private void connectTopVirtualSite(int row, int col) {
       if (row == 1) {
           grid.union(topIndex, convertToIndex(row, col));
           grid2.union(topIndex, convertToIndex(row, col));
       }
   }

   private void connectAdjacentSites(int row, int col) {
       connectTop(row, col);
       connectLeft(row, col);
       connectRight(row, col);
       connectBottom(row, col);
   }

   private void connectTop(int row, int col) {
       if (row > 1 && isOpen(row - 1, col)) {
           grid.union(convertToIndex(row - 1, col), convertToIndex(row, col));
           grid2.union(convertToIndex(row - 1, col), convertToIndex(row, col));
       }
   }

   private void connectLeft(int row, int col) {
       if (col > 1 && isOpen(row, col - 1)) {
           grid.union(convertToIndex(row, col - 1), convertToIndex(row, col));
           grid2.union(convertToIndex(row, col - 1), convertToIndex(row, col));
       }
   }

   private void connectRight(int row, int col) {
       if (col < gridLength && isOpen(row, col + 1)) {
           grid.union(convertToIndex(row, col), convertToIndex(row, col + 1));
           grid2.union(convertToIndex(row, col), convertToIndex(row, col + 1));
       }
   }

   private void connectBottom(int row, int col) {
       if (row < gridLength && isOpen(row + 1, col)) {
           grid.union(convertToIndex(row, col), convertToIndex(row + 1, col));
           grid2.union(convertToIndex(row, col), convertToIndex(row + 1, col));
       }
   }

   private void connectBottomVirtualSite(int row, int col) {
       if (row == gridLength) {
           grid2.union(convertToIndex(row, col), bottomIndex);
       }
   }

   private int convertToIndex(int row, int col) {
       return gridLength * (row - 1) + (col - 1);
   }

   public boolean isOpen(int row, int col) { // is site (row, col) open?
       if (row < 1 || row > gridLength || col < 1 || col > gridLength) {
           throw new IndexOutOfBoundsException();
       }
       return openSites[convertToIndex(row, col)];
   }

   public boolean isFull(int row, int col) { // is site (row, col) full?
       if (row < 1 || row > gridLength || col < 1 || col > gridLength) {
           throw new IndexOutOfBoundsException();
       }
       return grid.connected(convertToIndex(row, col), topIndex);
   }

   public     int numberOfOpenSites()  {     // number of open sites
       return numOpenSites;
   }

   public boolean percolates()  {            // does the system percolate?
       return grid2.connected(topIndex, bottomIndex);
   }

   //public static void main(String[] args)   // test client (optional)
}



import edu.princeton.cs.algs4.StdRandom;
import edu.princeton.cs.algs4.StdStats;
import edu.princeton.cs.algs4.WeightedQuickUnionUF;
import static java.lang.Math.sqrt;

public class PercolationStats {

    private double[] results;

    public PercolationStats(int n, int trials) {
        if (n <= 0 || trials <= 0) {
            throw new IllegalArgumentException();
        }
        results = new double[trials];

        //fill up results with the p values of every trial
        runExperiments(n, trials);
    }

    private void runExperiments(int n, int trials) {
        int row, col;

        for (int i = 0; i < trials; i++) {
            Percolation test = new Percolation(n);
            while (!test.percolates()) {
                //generate new random row and col
                row = StdRandom.uniform(n - 1) + 1;
                col = StdRandom.uniform(n - 1) + 1;
                test.open(row, col);
            }
            results[i] = (double)(test.numberOfOpenSites()) / (n * n);
        }
    }

    public double mean() {
        //return sample mean of all the p values
        return StdStats.mean(results);
    }

    public double stddev() {
        //return sample standard deviation of percolation threshold
        return StdStats.stddev(results);
    }

    public double confidenceLo() {
        return mean() - ((1.96 * stddev()) / sqrt(results.length));
    }

    public double confidenceHi() {
        return mean() + ((1.96 * stddev()) / sqrt(results.length));
    }

    public static void main(String[] args) {
        PercolationStats test = new PercolationStats(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
        System.out.println("mean                     = " + test.mean());
        System.out.println("stddev                   = " + test.stddev());
        System.out.println("95% confidence interval  = [" + test.confidenceLo() + ", " + test.confidenceHi() + "]");
    }    
}

这是我得到的错误,你能帮帮我吗。

String hql="from "+ Employee.class.getName()
                  + " where email= ? and password=? ";
List<Employee> emplist=ht.find(hql,email,pwd);

表格名为Hibernate: select employee0_.empid as empid0_, employee0_.empmail as empmail0_, employee0_.empmobile as empmobile0_, employee0_.empname as empname0_, employee0_.emppassword as emppassw5_0_ from emptab employee0_ where email=? and employee0_.emppassword=? com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'email' in 'where clause' 的格式化员工代码如下:

emptab

4 个答案:

答案 0 :(得分:1)

您的查询应该是:

String hql="from "+ Employee.class.getName()
                  + " e where e.mail= ? and e.password=? ";

确保电子邮件和密码字段已存在于您的数据库中的员工实体和员工表中。

答案 1 :(得分:0)

将单引号'放在?附近,因为电子邮件和密码是字符串,然后尝试

 String hql="from "+ Employee.class.getName()
            + " AS employee0_ where employee0_.empmail = ? and employee0_.emppassword=? ";
    List<Employee> emplist=ht.find(hql,email,pwd);

答案 2 :(得分:0)

问题在于你的hql查询,

String hql="from "+ Employee.class.getName()
                  + " where email= ? and password=? ";
List<Employee> emplist=ht.find(hql,email,pwd);

在上面的查询中,字段&#34; email&#34;在Employee类中不存在,将查询更改为,

String hql="from "+ Employee.class.getName()
                  + " where mail= ? and password=? ";
List<Employee> emplist=ht.find(hql,email,pwd);

通过此documentation,强烈推荐,

答案 3 :(得分:0)

异常表示无法找到email,您的Employee类中没有此类属性,实际上是mail,因此请更改您的查询

String hql="from "+ Employee.class.getName() + " where mail= ? and password= ? ";