how to create database and table using jsp

how to create database and table using jsp

hi frnds...., i want to create database and table in mysql using jsp.... i have an registration form(name,sex,address,phone and so on ... ) i want to create individual table in mysql for each user to store their details.. so pls help me how to create individual table using jsp code... the table name should be the name of the person in the registration form... pls its very urgent frnds.. i have tried with many code and its almost looking correct but its not working...

View Answers

August 23, 2012 at 5:39 PM

Here is a jsp code that create table into database according to the name entered by the user.

1)form.jsp:

<form name="form" method="post" action="table.jsp">
    <pre>
    Enter Name:    <input type="text" name="name" size="30"><br>
    Enter Gender : <input type="text" name="gender" size="30"><br>
    Enter Address: <input type="text" name="address" size="30"><br>
    Enter Phone :  <input type="text" name="phone" size="30"><br>

    <input type="submit" name="Submit" value="Submit">
    </pre>
    </form>

2)table.jsp:

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %> 
<html>
    <head>
        <title>display data from the table using jsp</title>
    </head>
    <body>
        <%
            String name=request.getParameter("name");
            String connectionURL = "jdbc:mysql://localhost:3306/test";
            Connection connection = null;
            Statement statement = null;
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                connection = DriverManager.getConnection(connectionURL, "root", "root");
                statement = connection.createStatement();
                String QueryString = "create table "+name+"(id int not null auto_increment,name " +
                        "varchar(25),gender varchar(20),address varchar(50),phone varchar(20), primary key(id));";
                statement.executeUpdate(QueryString);
                        %> 
                        Table of specified name is created successfully.
            <%      }
                        catch (Exception ex) {} 
                        finally {

                statement.close();
                connection.close();
            }
            %>
    </body>
</html>

August 23, 2012 at 5:59 PM

thank u for the code... its working good...


August 23, 2012 at 6:21 PM

Am having problem with the below code....

<link href="styles.css" rel="stylesheet" type="text/css"/>     
<%@page import="java.sql.*"%>
<%@ page import="java.io.*" %> 
<%
             String groupname = request.getParameter("groupname");
             String name = request.getParameter("name");
            String place = request.getParameter("place");
            String sex = request.getParameter("sex");
            String mobile = request.getParameter("mobile");

            try {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+groupname, "root", "root");
                Statement st = con.createStatement();
                Statement st1 = con.createStatement();
                 st.execute("create table memberdetail(groupname varchar(20),name varchar(20),place varchar(20),sex varchar(20),mobile int)");
                int i = st.executeUpdate("insert into memberdetail values('" + groupname + "','" + name + "','" + place + "','" + sex + "','" + mobile + "')");
            } catch (Exception e) {
                System.out.println(e);
            }
%>

i have created database for individual group based on the groupname... i lik to create table memberdetail and insert the details of the persons.. this code works gud to store single person... its not working wen i try to store more than 1 persons in memberdetail.. pls help me soon.....


December 30, 2014 at 9:35 PM


<%@page import="java.sql.*"%> <%@ page import="java.io.*" %> <% String groupname = request.getParameter("groupname"); String name = request.getParameter("name"); String place = request.getParameter("place"); String sex = request.getParameter("sex"); String mobile = request.getParameter("mobile");

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/,dbname ,"root", "root");
            Statement st = con.createStatement();
            Statement st1 = con.createStatement();
             st.execute("create table memberdetail(groupname varchar(20),name varchar(20),place varchar(20),sex varchar(20),mobile int)");
            int i = st.executeUpdate("insert into memberdetail values('" + groupname + "','" + name + "','" + place + "','" + sex + "','" + mobile + "')");
        } 
        catch (Exception e) 
        {
            System.out.println(e);
        }

%>

Ads









Related Tutorials/Questions & Answers:
how to create database and table using jsp
how to create database and table using jsp  hi frnds...., i want to create database and table in mysql using jsp.... i have an registration form(name... table using jsp code... the table name should be the name of the person
how to display values from database into table using jsp
how to display values from database into table using jsp  I want to display values from database into table based on condition in query, how to display that? For example i have some number of books in database but i want
Advertisements
how to upload an image from a jsp page to a mysql database table using jsp
how to upload an image from a jsp page to a mysql database table using jsp  how to upload an image from a jsp page to a mysql database table using jspstrong text
how to create bar chart in jsp using msaccess database
how to create bar chart in jsp using msaccess database  type... org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 10 in the jsp file: /bar.jsp Generated servlet error: C:\Program Files\Apache Software
how to create using jsp
how to create using jsp  code 1: <%@ page language="java...; <title>Create New Student</title> </head> <body> <form name="create" method="post" action="<
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript  when click on the next... to display previous 10records. Database Query like this: Select * from table
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
how to fetch data from mysql database table and draw a bar chart on that data using in jsp  how to create bar chart fetch data from mysql database using in jsp.please give me a right code. yhanks in advance
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  thanks for reply...) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758) org.apache.jsp.bar<em>jsp.</em>...) org.apache.jsp.bar<em>jsp.</em>jspService(bar_jsp.java:57
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  type Exception... org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 8 in the jsp... Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:57
how to use String tokenizer on table that is retrieved from database using jsp servlet
how to use String tokenizer on table that is retrieved from database using jsp servlet  Query:Table---- mysql> select pid,medicinename,dose,day,qty from medicinedetails2 where pid=15
Retrieve database from the table dynamically in jsp from oracle using servlet
Retrieve database from the table dynamically in jsp from oracle using servlet  Sir, I have created a table in oracle using eclipse, and added few... using java servlet from the database in the jsp page
How to create bar chart using database values
How to create bar chart using database values  How to create bar chart using database values i.e excellent,good,average fields using jsp?It is like opinion poll.I want to show how many votes are came for excellent,good,average
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
Create a Table in Mysql database through SQL Query in JSP
Create a Table in Mysql database through SQL Query in JSP...; This is detailed java code to connect a jsp page to mysql database and create a table of given...;head> <title>Create table in mysql database using jsp<
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
how to create online exam in jsp and database
how to create online exam in jsp and database  learing stage ,want to know how to create online exam
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database... to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts... example using struts.if anyone knows how to do it..please help me.. thanks a lot
how to create bean using jsp and servlet
how to create bean using jsp and servlet  public class SampleBean... the following links: http://www.roseindia.net/jsp/usingbeansinjsp.shtml http://www.roseindia.net/jsp/loginbean.shtml
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?  I have a project ie create an application for users to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts
how to insert data in database using html+jsp
how to insert data in database using html+jsp  anyone know what is wrong with my code? print("<% /* Create string...").newInstance(); /* Create a connection by using getConnection() method
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  how to insert check box value to the database using jsp my code is <link href...;table cellspacing="10" cellpadding="6" align="center" border="0" bgcolor="#D8E2F4
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's package. where the admin will select the activities to insert in the PACKAGE table. I
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's package. where the admin will select the activities to insert in the PACKAGE table. I
How to search the selected item in row table using radia button in JSP?
How to search the selected item in row table using radia button in JSP?  How to search the selected item in row table using radia button in JSP
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap.  I have a jsp page which ask for project ID,team name,member name according to this data i have to retrieve their details from the database(oracle). I have
How to retrive database information using servlet and disply in table format in browser
How to retrive database information using servlet and disply in table format in browser  Hi, any one send code how to retrive the data base information in table format in web browser
how to store data in other table using servlet and jsp
how to store data in other table using servlet and jsp  pls can anyone tell how to store data in other table using servlet and jsp and want to display that data too.and the data in first table must be same.pls help
How to retrieve image from database using jsp and servlet?
How to retrieve image from database using jsp and servlet?  Hi, I am trying to find code for displaying the image from database in a JSP page. How to retrieve image from database using jsp and servlet
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse  please help me i have to submit this soon

Ads