Professional Documents
Culture Documents
Advance codes
Massage dialogs
Normal massage dialog JOptionPane.showMessageDialog(null, "click"); Warning massage dialog box Object[] options = { "YES", "CANCEL" }; int respon = JOptionPane.showOptionDialog(null, "Are You Sure You want to Proceed", "Warning",JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,null, options, options[0]); if(respon==0){ System.out.println( this is YES ); }
Sql Queries
Sql query to get the last row SELECT * FROM users ORDER BY userid DESC LIMIT 1
Sql query example to use logics select* from project where (ProjectType = '"+Type+"')&&(RequestID = '"+RequesId1+"')
Adding a image to Database using prepared statement(sql data type should set to blob)
String fName = "C:/Documents and Settings/PC/My Documents/My Pictures/birthday-cat.jpg"; File f = new File(fName); FileInputStream in; try { in = new FileInputStream(f); byte[] image = new byte[(int) f.length()]; in.read(image); Connection con = DB.getMyConnection(); Statement st = con.createStatement(); String sql = "insert into students(studentpic,name) values(?,?)"; PreparedStatement stmt = (PreparedStatement) con.prepareStatement(sql); stmt.setBytes(1, image);
Password encrypt
import java.security.MessageDigest; public class EncryptExample { public static void main(String[] args) { String password = "secret"; String algorithm = "SHA"; byte[] plainText = password.getBytes(); MessageDigest md = null; try { md = MessageDigest.getInstance(algorithm); } catch (Exception e) { e.printStackTrace(); } md.reset(); md.update(plainText); byte[] encodedPassword = md.digest(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < encodedPassword.length; i++) { if ((encodedPassword[i] & 0xff) < 0x10) { sb.append("0"); } sb.append(Long.toString(encodedPassword[i] & 0xff, 16)); } System.out.println("Plain : " + password); System.out.println("Encrypted: " + sb.toString()); } }
al.remove("F"); al.remove(2);
Absolute path
this.getClass().getResource("zero.au").toString() System.getProperty("user.dir") + "/src/" + path
//-- Define one or more of these to handle keyboard events public void keyPressed(KeyEvent e) {. . .} public void keyReleased(KeyEvent e){. . .} public void keyTyped(KeyEvent e) } {. . .}