Example usage for jdk.nashorn.internal.objects NativeString trim

List of usage examples for jdk.nashorn.internal.objects NativeString trim

Introduction

In this page you can find the example usage for jdk.nashorn.internal.objects NativeString trim.

Prototype

@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String trim(final Object self) 

Source Link

Document

ECMA 15.5.4.20 String.prototype.trim ( )

Usage

From source file:serverproject.DatabaseConnection.java

public static ResultSet find_user_by_username(String username) {
    try {//  ww w  . j a  v a2 s. c o  m

        username = NativeString.trim(username);

        PreparedStatement ps = con.prepareStatement("SELECT * FROM chat_users WHERE username=? LIMIT 1"); //need to check if the user is already logged in

        ps.setString(1, username);

        //            Statement s = con.createStatement();
        //
        //            ResultSet rs = s.executeQuery("SELECT * FROM users WHERE username = '" + username + "'");
        ResultSet rs = ps.executeQuery();

        return rs;

    } catch (SQLException ex) {
        System.out.println("find user Error: " + ex);
        return null;
    }
}

From source file:serverproject.DatabaseConnection.java

public static boolean insertUser(String name, String userName, String password) {
    try {//from   w ww  .j av a 2 s.  c om
        name = NativeString.trim(name);
        userName = NativeString.trim(userName);
        password = NativeString.trim(password);

        //shaafi 27-7-16 start
        //checking if the username already exists or not
        ResultSet re = find_user_by_username(userName);
        if (re.next()) { //if username already exists,,show a msg and return false
            if (userName.equalsIgnoreCase(re.getString("username"))) {
                return false;
            }
        }

        String statement = "INSERT INTO chat_users (name,userName, password) VALUES (?, ?, ?)";

        PreparedStatement ps = con.prepareCall(statement);
        ps.setString(1, name);
        ps.setString(2, userName);
        ps.setString(3, password);
        //ps.setString(4, gender);

        int temp = ps.executeUpdate();

        return temp != 0;

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Insert error: " + e.getMessage());
        return false;
    }
}