Results 1 to 2 of 2
  1. #1
    avisik is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default General Insert statement to DB

    Hello everybody,

    i have a question.
    i am working on a project, and i want it to have a package that holds all the GUI classes and a package to hold the DB classes.

    i work with MySql and Eclipse.

    i have a class "MySqlConnection" that have a method called "InsertToTable", i want this method to be general.

    what i mean?
    let's say for example i have this class in the GUI that have a button that when pressed it Inserts the fields the user filled into the DB.
    for example the fields are: book_name,author_name.

    i want that the button in the GUI will send a TreeMap that contains the data the user typed and it will send it to "InsertToTable" method. and the "InsertToTable" will actually insert the data it received with a Prepared Statement.

    that's all good but, i want "InsertToTable" to be general, if now i work with another GUI that it job is to insert data to a table that has 5 columns i want this method to deal with 5 columns, and with any number of columns, so it would be as general as possible.
    i know how to use Prepared Statements with question marks, but i don't know how to use the same Prepared Statement for different tables that will deal with different number of columns.

    Thanks in advance :)

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Pass the column and table names and "build" the statement (using as many ?'s as provided column names) and use DatabaseMetaData to get the column types (or maybe attempt to determine it by looking at the Data, or try to let the Driver determine it with setObject).

Similar Threads

  1. General Java Help
    By ST34LTH in forum New To Java
    Replies: 2
    Last Post: 11-07-2010, 04:57 PM
  2. general help.
    By socboy6579 in forum New To Java
    Replies: 1
    Last Post: 10-24-2010, 11:41 PM
  3. general help.
    By socboy6579 in forum New To Java
    Replies: 1
    Last Post: 10-24-2010, 10:20 PM
  4. insert statement return problem in ibatis
    By dheerajsea123 in forum JDBC
    Replies: 1
    Last Post: 05-20-2010, 11:22 AM
  5. Replies: 3
    Last Post: 02-28-2009, 10:17 AM

Posting Permissions

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