how to take input table name in jsp to create table in mysql?
Hello Friend,
Try the following code:
<%@page import="java.sql.*"%> <form method="post"> Enter Table Name:<input type="text" name="table"><input type="submit" value="Create Table"> </form> <% String tab=request.getParameter("table"); try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "root"); Statement st = con.createStatement(); String table = "CREATE TABLE "+tab+"(id integer, name varchar(100), address varchar(100))"; System.out.println(table); st.executeUpdate(table); out.println("Table is created successfully!"); } catch (Exception e){ e.printStackTrace(); } %>
Thanks
Ads