some Java Test
Java
code posted
by
zupzup
created at 15 Dec 17:13
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public static bool isUsernameValid(string username) { RegEx r = new Regex(“^[A-Za-z0-9]{16}$”); return r.isMatch(username); } // java.sql.Connection conn is set elsewhere for brevity. PreparedStatement ps = null; RecordSet rs = null; try { pUserName = request.getParameter(“UserName”); if ( isUsernameValid (pUsername); ps = conn.prepareStatement(“SELECT * FROM user_table WHERE username = ? ”); ps.setString(1, pUsername); rs = ps.execute(); if ( rs.next() ) { // do the work of making the user record active in some way } } else { // handle invalid input } } catch (…) { // handle all exceptions … } |
731 Bytes in 4 ms with coderay