Posts

How to use Url-rewriting using Java in NetBeansIDE

Image
URL Rewriting format - (  url?paramName=paramValue   )   1. In your web project make web page (say index.jsp) having a link as:    <a href="FetchDataServlet">Fetch Data from DB...</a> 2. Make a Servlet (say 'FetchDataServlet') and write code to fetch all the record on web         page.         try {                        Class.forName("com.mysql.jdbc.Driver");             Connection con = DriverManager.getConnection("jdbc:mysql://localhost/testdb", "root", "root");             PreparedStatement ps = con.prepareStatement("select * from test2");             ResultSet rs = ps.executeQuery();  ...

How to Detect CapsLock key using Java in NetBeansIDE.

Image
How to Detect CapsLock key using Java in NetBeansIDE. Note: packages and classes used: - java.awt.Toolkit; - java.awt.event.KeyEvent; 1. Open NetBeansIDE. 2. Make a new project say DemoCaps. 3. Make a new JFrame Form in it say CapsLockDetect and design it. 4. RC on Form and Goto Properties~Events~KeyPressed~Select formKeyPressed. 5. Write the following code in the method and Fix all imports:    if(Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK))    {        jLabel.setText("ON");    }    else    {        jLabel.setText("OFF");    } 6. Run the Project. 7. Finish. Thank You :)

How to display record in a table on web page using Servlet, using JAVA in NetBeansIDE

Image
  How to display record in a table on web page using Servlet, using JAVA in NetBeansIDE. 1. Open NetBeansIDE 2. In your project, make a new Servlet (say 'GetDataServlet') 3. In servlet write the code in 'processRequest' method      Code Download : http://www.4shared.com/office/-Z7OvgNO/display_record.html 4. Make a hyperlink in index.jsp with href="GetDataServlet" or as in web.xml 5. Add required JAR in Libraries folder. 6. Run your project. 7. Finish Facebook Page : https://www.facebook.com/pages/Raks/335960303097841 Description:  

How to call private method of a class using Java in NetBeansIDE

Image
Steps: 1. Open NetBeansIDE. 2. In your project make a class file. 3. In your class file make a class, say 'C' with a private method. 4. Make another class say 'Calling' and write the following code in it:     public static void main(String[] args)throws Exception {                 Class c=C.class;         Object obj=c.newInstance();         Method m=c.getDeclaredMethod("msg", null);         m.setAccessible(true);         m.invoke(obj, null);             } 5. Run the file. 6. Finish. Thank You :)

How to take snapshot of screen in Java using NetBeansIDE

Image
How to take snapshot of screen in Java using NetBeansIDE. 1. Open NetBeansIDE. 2. Make a JFrame Form and design it. 3. RC on a button and Goto Events~action~actionPerformed 4. Write following code in it. Note: createScreenCapture(Rectangle rect) method is used to capture screen. It is the method of Robot class. try{ BufferedImage image=new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); ImageIO.write(image,"jpeg",new File(your path)); ImageIcon icon=new ImageIcon(image); jLabel1.setIcon(icon); }catch(Exception e) { e.printStackTrace(); } 5. Run your Project. 6. Finish. Thank You :) Facebook Page

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{                    ...