How to populate Drop Down From Database Table in Java

Before create project you have to understand from a JSP file you have to create JDBC Connection with default port 3306  and call HTML Code inside JSP page :--

==========================index.jsp====================================




<%@ page import="java.sql.*" %>
<%ResultSet resultset =null;%>

<HTML>
<HEAD>
    <TITLE>Welcome in Java by Anand,Bangalore</TITLE>
</HEAD>

<BODY BGCOLOR=#66CCFF>

<%
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/Anand";
con = DriverManager.getConnection(url, "root", "pass@123");
    Statement statement = con.createStatement() ;
    resultset =statement.executeQuery("select * from blore") ;
%>

      <center>
    <h1> Welcome in Java by Anand,Bangalore</h1>
        <select>
        <%  while(resultset.next()){ %>
            <option><%= resultset.getString(2)%></option>
        <% } %>
        </select>
     </center>

<%

        }
        catch(Exception e)
        {
             out.println("wrong entry"+e);
        }
%>

</BODY>
</HTML>

======================Create Table Form DB=========================

> Create Database Anand;
> use Anand;
> Create table blore(id int(4), city varchar(30));;
>  insert into blore values('1',"Rewa");
insert into blore values('2',"Pune");
insert into blore values('3',"Bangalore");
insert into blore values('4',"Satna");


Comments

Popular posts from this blog

Converting JSONArray into CSV file in java

Online Book Store Website Using Java

How to read CSV File in Java