Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help in creating dynamic table in database

    hi, i want to create or alter dynamic table in database using jsp..

    is there a way to create or alter them?

    note: i am not talking about creating dynamic table in html

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This is going to come down to your database of choice, and not the language. In MySQL there is a create temporary table reference, though I see little to no reason to ever use it (I've used temporary tables for migration of data, nothing else as proper structure should eliminate the need for temporary tables). Except in Access of course, where you are constantly having to figure out ways around its... limitations.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i using Mysql..
    do i need to set anything in mysql?
    and can i have a sample code to create a table to understand better?

    altering the table will be same way as creating a table by using temporary table reference?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Here is the page for the CREATE TABLE DDS in MySQL. You'll need to use this to develop the table for proper datatypes of the data you are expecting to put into it:
    http://dev.mysql.com/doc/refman/5.5/...ate-table.html
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New Coder
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    but how do i write in jsp?

    example:
    Code:
    String sql="insert into sample (id) values(?)";
    PreparedStatement pstmt=conn.prepareStatement(sql);
    pstmt.setString(1,"abc");
    pstmt.executeUpdate();

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    That looks right to me, yeah.
    I'm not certain that DDS statements are usable with prepared statements; as I mentioned I've only needed dynamic tables during migration of data so I've never tried to use prepared statements with them. To me, it doesn't make any sense to create a dynamic table with a prepared statement, though you should be able to create the queries for it as prepared statements.
    The connection class includes a createStatement method which allows you to create a Statement instead of a PreparedStatement object. This can be run with the .execute(sql) directly if you are not using prepared statements.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    New Coder
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i am trying to create a super simple table for trying out.
    But it keep getting error.

    Error
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''abc' ('id' INT)'

    Codes
    Code:
            String sqlCommand="Create table IF NOT EXISTS 'abc' ('id' INT)";
            Statement stmt=conn.createStatement();
            stmt.execute(sqlCommand);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •