Skip to main content

Posts

Showing posts from November, 2015

Setting up a database connection (Java+mysql)

Initially, it is essential to set up the database connection. STEP 1: Create a database in phpmyadmin and create the required table. STEP 2: Set up a new connection in Net Beans. 1. Right Click on Databases (Services tab) -> Select New Connection 2. Select MySQL  -> Select Next 3. Enter the name of your database -> TEST   CONNECTION 4. If you see the below added to your services, then the connection has been set up successfully. STEP 3: Add a library to the net beans project as below. STEP 4:     Creating the Database Connect Class 1. Create a new package under the project and create a new class called ' DBconnect ' under that package. 2. DBconnect class should look like below.  In the line,         con = (Connection) DriverManager.getConnection(" jdbc:mysql://localhost:3306/employee ","root",""); The highlighted path can be optained from the services pane where we es

Implementing Data Structures using Java - Stacks

The Stack Data Structure follows the principle of Last In First Out which means the last element inserted is the one to be taken out first.  Real world example would be a stack of CDs. To take out the bottom one you will have to remove the CDs on top of it. And in this Data Structure you have to remove each element one by one. This example is implemented using an array, hence contains elements of the same data type only. A Stack comes in handy when you need to reverse a character array and this will show you how. STEP 1: The Stack class should be implemented as below. STEP 2: The GUI should be designed as preferred. Then, the Stack is created dynamically in case it needs to be accessed in different events and for the button click the below code should be added. STEP 3: An object of the JFrame Class (GUI) should be created in the main program and the visibility should be set to true. Now, you can run the program and use it to reverse any string.