小编czu*_*upe的帖子

SQL COUNT*GROUP BY大于,

我想选择带有出现次数的不同键,这个查询似乎是有效的:

SELECT ItemMetaData.KEY, ItemMetaData.VALUE, count(*) 
FROM ItemMetaData 
GROUP BY ItemMetaData.KEY 
ORDER BY count(*) desc;
Run Code Online (Sandbox Code Playgroud)

但我也希望过滤这些结果,这意味着我只想在count(*)大于2500的地方,所以只显示大于2500的结果,但是:

SELECT * 
FROM 
(
    SELECT ItemMetaData.KEY, ItemMetaData.VALUE, count(*) 
    FROM ItemMetaData 
    GROUP BY ItemMetaData.KEY 
    ORDER BY count(*) desc
) as result WHERE count(*)>2500;
Run Code Online (Sandbox Code Playgroud)

不幸的是,此查询会导致语法错误.你能帮我实现我的要求吗?

sql group-by count

36
推荐指数
4
解决办法
6万
查看次数

Vaadin认证最佳实践

我对Vaadin中的身份验证最佳实践感兴趣我认为这里主要有两种选择:

  • ThreadLocal(可能导致内存不足,可以为不同的用户提供相同的线程)
  • Spring Security + Vaadin集成(看起来有点过分)

您更喜欢哪一个?为什么?(安全问题,易开发,其他因素)

authentication spring-security vaadin

18
推荐指数
1
解决办法
2万
查看次数

通过JAVA中的gmail smtp服务器发送电子邮件

这段代码有什么问题?不知怎的,它进入了线路的无限循环 Transport.send(message);,没有错误信息,没有异常,只是可能无限循环(我不知道因为我不等待超过5-10分钟)

final String username = "<mail_name>";
final String password = "<password>";

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");

Session session = Session.getInstance(props,
        new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });

try {

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress("<mail_from>@gmail.com"));
    message.setRecipients(Message.RecipientType.TO,
            InternetAddress.parse("<mail_to>@gmail.com"));
    message.setSubject("Test Subject");
    message.setText("Test");

    Transport.send(message);

    System.out.println("Done");

} catch (MessagingException e) {
    throw new RuntimeException(e);
}
Run Code Online (Sandbox Code Playgroud)

java smtp jakarta-mail

14
推荐指数
1
解决办法
8万
查看次数

Java Enum类型编码公约

我有一个枚举类型......

public static enum Methods {
    NOTEQUAL,
    ORDERED,
    minMatch,
    minItem,
    minLength,
    sameLength,
}
Run Code Online (Sandbox Code Playgroud)

问题是我应该如何使用编码约定.我应该使用camelCase NotEqual(我在一个简单的类中使用)还是应该这样做:NOT_EQUAL?或者只是使用大写字符:NOTEQUAL,SAMELENGTH

这有什么代码约定吗?

java enums coding-style

11
推荐指数
1
解决办法
3万
查看次数

REGEXP在非字母数字而非空格,' - '字符上有效

我想只找到非字母数字字符,只有没有空格而没有'-'...

但这不起作用:

REGEXP '^[a-zA-Z0-9/-:space:]*'
Run Code Online (Sandbox Code Playgroud)

此正则表达式对这些数据有效:

 'Test Cinema'
  'AMERICANII AU TALENT - SEZONUL 5, EPISODUL 12'
Run Code Online (Sandbox Code Playgroud)

我不想找到这些字符,我想找到这样的字段:

'Test Item;?!'
'LOCAL KOMBAT "FIERBE BULGARIA"'
Run Code Online (Sandbox Code Playgroud)

如何编写仅对其他字符有效的正则表达式.

regex mysql

3
推荐指数
1
解决办法
3355
查看次数

GWT +序列化

我很难尝试序列化我的课程(实际上是3-4个小时才找到解决方案).我将一个子类添加到现有的可序列化和正常运行的类中,并获取以下错误消息:

 [ERROR] com.google.gwt.user.client.ui.DelegatingChangeListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.google.gwt.user.client.ui.DelegatingClickListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.google.gwt.user.client.ui.DelegatingFocusListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.google.gwt.user.client.ui.DelegatingKeyboardListenerCollection is not …
Run Code Online (Sandbox Code Playgroud)

gwt serialization subclass

2
推荐指数
1
解决办法
7143
查看次数

HTML表总是在新行?

如果我像这样创建一个HTML表:

text text text
    <table border='0'>
     <TR>
        Table Item
     </TR>
    </table>
Run Code Online (Sandbox Code Playgroud)

这总是会生成一个新行吗?)--------------->

text text text
 Table Item
Run Code Online (Sandbox Code Playgroud)

没有机会像这样生成(所以没有换行?)--------------------->

tex text text  Table Item
Run Code Online (Sandbox Code Playgroud)

html newline html-table

2
推荐指数
2
解决办法
8472
查看次数

Java Filter无限循环

我想实现一个过滤器来进行身份验证,但不知何故,它被卡在无限循环中...任何想法都赞赏.

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    doBeforeProcessing(request, response);

    Throwable problem = null;
    HttpSession session = httpRequest.getSession(true);
    if(session.getAttribute("userName")!=null&&session.getAttribute("userName")!=(""))
    {
        try {
            chain.doFilter(request, response);
        } catch (Throwable t) {
            // If an exception is thrown somewhere down the filter chain,
            // we still want to execute our after processing, and then
            // rethrow the problem after that.
            problem = t;
            t.printStackTrace();
        }   
    }else{
        httpResponse.sendRedirect("login.jsp");
        return;
    }
Run Code Online (Sandbox Code Playgroud)

这个代码在调试模式下运行无限次,基本上我想在用户没有登录时将用户重定向到login.jsp.任何答案都可以.

java authentication servlets infinite-loop servlet-filters

2
推荐指数
2
解决办法
7000
查看次数

是否可以在没有外键的情况下使用 Hibernate

一个简单的问题,如果有人可能有此主题的经验:

是否可以在表中使用没有外键的 Hibernate(具有完整功能)...?

就我而言,我需要这个,因为我想要reverse engineering a liferay database和实体,而在liferay中,外键只会搞乱事情(Liferay不支持外键),所以如果我可以关闭外键更改,这将是一个很好的解决方案在某些休眠参数中(我知道它不起作用,所以可能需要一些解决方法)

hibernate foreign-keys liferay

2
推荐指数
1
解决办法
4028
查看次数

字符串到日期转换(一切似乎都很好,但失败)

如何解析这个字符串?

"Mon Jul 02 13:49:16 CEST 2012"

String Date = "Mon Jul 02 13:11:38 CEST 2012";
DateFormat formatter;
Date convertedDate= new Date();
formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
try {
     convertedDate = (Date) formatter.parse(Date);
} catch (ParseException ex) {
    Logger.getLogger(ItemRecTestCases.class.getName()).log(Level.SEVERE, null, ex);
        }
Run Code Online (Sandbox Code Playgroud)

不工作......" java.text.ParseException: Unparseable date:"

java date date-conversion

1
推荐指数
2
解决办法
183
查看次数

在一般方法中使用instanceof

我今天开始学习仿制药,但这对我来说有些奇怪:

我有一个通用的方法:

  public<T> HashMap<String, T> getAllEntitySameType(T type) {

        System.out.println(type.getClass());
        HashMap<String, T> result = null;

        if(type instanceof Project)
        {
            System.out.println(type.toString());
            System.out.println("Yes, instance of Project;");
        }

        if(type instanceof String)
        {
            System.out.println(type.toString());
            System.out.println("Yes, instance of String;");
        }
        this.getProjects();
        return result;
    }
Run Code Online (Sandbox Code Playgroud)

我可以轻松确定T类的类

    Project<Double> project = new Project<Double>();
    company2.getAllEntitySameType(project);
    company2.getAllEntitySameType("TestString");
Run Code Online (Sandbox Code Playgroud)

输出将是:

class Project
Yes, instance of Project;
class java.lang.String
TestString
Yes, instance of String;
Run Code Online (Sandbox Code Playgroud)

我认为在泛型中我们不能使用实例.据我所知,有些东西并不完整.谢谢...

java generics instanceof

1
推荐指数
1
解决办法
964
查看次数

线程似乎工作正常,但不应该

我有一个程序,任务是证明我的班级不是线程安全的,但我得到了很好的结果,但可以"明白为什么......

应用程序基本上将所有工作人员的工资增加一倍,并且执行1000次并使用100个线程,因此结果应该增加100.000,并且可以:/

测试类:

final int THREADGROUPSIZE = 100;
        Thread threads[] = new Thread[THREADGROUPSIZE];

        for (int i=0; i <THREADGROUPSIZE; ++i) {
            threads[i] = new Thread(new CompManagerThread());
            threads[i].run();
        }

        for (int i=0; i <THREADGROUPSIZE; ++i) {
            try {
                threads[i].join();
            }
            catch (InterruptedException e) {
                System.out.print("Join interrupted\n");
            }
        }

        System.out.print("Waiting for threads to complete\n");
        System.out.println("-------PRINTING THREADED WORKERS----------");
        Company threadCompany = Company.getInstance();
        ArrayList<Worker> workerThreadArray = threadCompany.GetWorkersOrderedInSalary();
        for (Worker worker : workerThreadArray) {
            System.out.println(worker);
        }

        System.out.println("-------PRINTING ORIGIN WORKERS----------");
        ArrayList<Worker> workerArray = companyFromHSQL.GetWorkersOrderedInSalary();
        for (Worker worker …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading

1
推荐指数
1
解决办法
75
查看次数