Monday 18 July 2016

Important Queries in Mysql



1. How to change datatype of column

ALTER TABLE `tablename`.`period`
CHANGE COLUMN `PERIOD_NO` `PERIOD_NO` INT(20) NULL DEFAULT NULL ;


2.How to add  column name

alter table productinfo
add column DEMO_CALL_NO2 VARCHAR(45) AFTER DEMO_CALL_NO;

3.How to rename existing table name

rename table userinfoTable to productinfoTable

4.How to rename existing column name

ALTER TABLE productinfo
CHANGE COLUMN DEMO_CALL_NO DEMO_CALL_NO1 VARCHAR(45)

5.How to add primary key with autoincrement in existing table

alter table productinfo

add column PRD_ID int not null auto_increment primary key first


6.How to drop existing column from table

alter table productinfo

drop column PRD_ID

7. How to default value to existing column

ALTER TABLE mattress_multiple
MODIFY COLUMN FOAM_STATUS VARCHAR(45) NOT NULL DEFAULT 0



Coming Soon...............................

Sunday 17 July 2016

HOW TO FETCH DATA FROM DATABASE INTO JSP IN A DROPDOWN AS A LIST




STEP 1. Write query of jdbc like create connection,statment and result set to get data with in scriptlet code of jsp

code will be like this---


    <% 
                     Statement stmt=null;
                     
                 Connection    con=DatabaseConnect.getConnection();
                     stmt=con.createStatement();
                     ResultSet resultSet=stmt.executeQuery("select CITY_NAME from city");
                     
                     
                      
                      %>

Please dont get confuse from jdbc code, i used according to me, but you can write according to you.

STEP 2. Now, write code for dropdownlist


 <select class="select2_single form-control"  tabindex="-1" name="city">
                                             
                                             <option >Select City</option>
                                             
                                             <% while(resultSet.next()){ %>
                                             
                                             <option><%=resultSet.getString("CITY_NAME") %>
                                             
                                             <%} %>
                                             
                                             
                                               </select>


Note- In database, there is a table CITY, and CITY_NAME is column name.



Thanks

Keep Happy Learning....