Posts

Showing posts from August, 2013

How to get Image from Database(MySQL) in Java with NetBeansIDE.

Image
How to get Image from Database(MySQL) in Java with NetBeansIDE Note: Image is of Blob/LongBlob type in Database. 1. Open NetBeansIDE. 2. In your project make a JFrame form (say NewForm)    2.1 Add a button and a label(to display the image) in it. 3. Right Click on Button and Goto Events~action~actionPerformed    3.1 In actionPerformed method write code for connection.    3.2 Get the image in Byte array. 4. Import mysql connector jar file. 5. Run the JFrame Form file. 6. Finish. Thank You :) Facebook Page

How to insert Image in MySQL Database with Java in NetBeansIDE

Image
How to insert Image in MySQL Database with Java in NetBeansIDE. 1. Open NetBeansIDE 2. Make a new Java Application project. 3. Make a JFrame Form and Design it as in this project. 4. Right Click on 'Choose File' button and Goto events~action~actionPerformed 5. Make a table in your MySQL DB say 'Image' with one Image column of LongBlob type. 6. Enter the code in it(in actionPerformed for Choose File Button).    (Fix all imports)         JFileChooser fc=new JFileChooser();         fc.showOpenDialog(this);         File f=fc.getSelectedFile();         String path=f.getAbsolutePath();         jLabel1.setIcon(new ImageIcon(path));         try{                         FileInputStream fin=new FileInputStream(f);             int len=(int)f.length();                         Class.forName("com.mysql.jdbc.Driver");             Connection con=DriverManager.getConnection("jdbc:mysql://localhost/new", "root", "root"

How to Perform DES Encryption and Decryption of TXT file in JAVA with NetBeansIDE

Image
1. Open NetBeansIDE. 2. Make a JFrame Form say EncryptTXT.java , I have already made it.               3. Make a class named DESEncrypt.java enter codes and Fix All Imports(It is necessary)     3.1 Write code in it            public static void encrypt(String key, InputStream is, OutputStream os) throws Exception {                                 encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);                 }                 public static void decrypt(String key, InputStream is, OutputStream os) throws Exception {                                 encryptOrDecrypt(key, Cipher.DECRYPT_MODE, is, os);                 }                 public static void encryptOrDecrypt(String key, int mode, InputStream is, OutputStream os) throws Exception {                                 DESKeySpec dks = new DESKeySpec(key.getBytes());                                 SecretKeyFactory skf

How to make a simple Login page using Servlet & Session in NetBeans IDE

Image
How to make a simple Login page using Servlet & Session in NetBeans IDE 1. Open NetBeans IDE 2. Make a new Project as:    2.1 File~NewProject~Java Web~WebApplication 3. Make a servlet(say First.java) as:    3.1 RightClick on Source Package~New~Other~Web~Servlet    3.2 Name your Servlet    3.3 Check Add Information to deployment descriptor(web.xml file) 4. Make another servlet(say Second.java). 5. Make an HTML file as:    5.1 RC on Web Pages folder and select New~Other~Web~HTML    5.2 Design a simple form in HTML    5.3 Give the url-pattern of First Servlet in the 'action' attribute(say '/First') 6. Write code for First.java to authenticate the user       6.1 In this servlet set the session attribute with a 'key' and its 'value'. 7. Write code for Second.java to view the profile    7.1 In this get the attribute of session. 8. Run the Project(let server is Tomcat). 9. Finish. Facebook

How to validate 'email' using Regular Expression in Java with NetBeansIDE

Image
How to validate 'email' using Regular Expression in Java with NetBeansIDE 1. Open NetBeansIDE 2. In your project Make a java form(e.g. JFrame Form)    2.1 Design this Form with one JTextField and a button in it. 3. Make Validate.java class        3.1 In this class make a static method with code:        public static boolean validateEmail(String email) {                                                boolean status=false;           String EMAIL_PATTERN =         "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"         + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";        Pattern pattern = Pattern.compile(EMAIL_PATTERN);        Matcher matcher=pattern.matcher(email);        if(matcher.matches())        {            status=true;        }        else{            status=false;        }            return status;                 } 4. Right Click on Button and Goto Events~Action~actionPerformed    4.1 In this method Call the 'validateEmail' method of Va