SQL安全的空值时打印错误

问题描述 投票:0回答:1

JTextfield为空时,如何打印“错误”

save.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)
    {
        String sn =jX1.getText();
        if (sn==null){
            System.out.println("Error");
            System.out.println("T");
        }

谢谢

if-statement jtextfield
1个回答
0
投票

尝试使用故障安全方法。同时扩展注释,您应该以更好的格式记录数据。 Java托管了大量不同的记录特定数据的方法。 look here

至于你的错误处理,try-catch-finally。这不是经过测试的代码。如果您遇到任何问题,请参阅try-catch和其他语句herehere的文档。

    public static void main(String[] args) {
    while (String sn == null)
    try {
         String sn = JX1.getText();
    } catch (Exception ex) {
        System.out.println("Exception thrown!");
    }  finally {
    if (sn != null) { 
        System.out.println("Closing PrintWriter");
        sn.close();
    } else { 
        System.out.println("PrintWriter not open");
    } 
} 
© www.soinside.com 2019 - 2024. All rights reserved.