rohit
how to take input table name in jsp to create table in mysql?
1 Answer(s)      4 years and 8 months ago
Posted in : JSP-Servlet

how to take input table name in jsp to create table in mysql?

Advertisement
View Answers

November 19, 2010 at 10:55 AM


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










Related Tutorials/Questions & Answers:
Advertisements