Consider a situation where the requirement of the client gets changed and you have asked to modify the structure of the table. In reality it is the work of the database administrator but as a Java programmer you should know how you can modify the structure of the table. The problem is that we have to add a new column to our database by using the java program. There is no need to get panic. What we simply need is to use a query for adding a new column in the database table.
To get the desired result firstly we need to make a connection with our database. After connection has been established pass the query in the prepareStatement() for adding new column in the database. This method will return the PreparedStatement object. By the object of the PreparedStatement we will call the executeUpdate() which will tell the status of the table.
The code of the example is given below:
web.xml file for this program:
The output of the program is given below:
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: July 17, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles