I am trying to implement a Servlet with JDBC.
My idea is that when user log in using the login form, he will be able to see the list off available databases in the MySQL. So I'm generating that dynamically on Servlet. That databases are displayed to the user using dropdown list.
Now when user clicks on any of the available databases I am using JavaScript to check which database is selected by the user. Now I want to retrieve that value into my servlet from JavaScript. Based on the selected database i want to display the list of available tables in the database to the user.
Is this possible? If not then is there any other way to do so??
Here is the sample code that generates drop down menu dynamically.
ResultSet r = dbmetadata.getCatalogs();
ResultSetMetaData metadata = r.getMetaData();
int colCount = metadata.getColumnCount();
int i;
out.println("<select id='db' name='db'onChange= 'myFunction();'>");
out.println("<option value = -1>--Select Database--</option>");
int value = 1;
while(r.next())
{
for(i=1;i<=colCount;i++)
{
out.println("<option value = " + value + ">" + r.getString(i) + "</option>");
}
k++;
}
out.println("</select>");
JavaScript code looks something like this:
function myFunction()
{
var select = document.getElementById("db");
var dbSelected = select.options[select.selectedIndex].text;
var x = document.getElementById("dbs");
x.innerHTML = "You have selected " + dbSelected;
};
Thank You :)