• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing table name and table structure during run time?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone
I am new to jdbc programming. I am trying to design a jdbc application through wich user will be able to pass table name and table structure during run time. My program would ask the user to pass table name and table fields through the console then it would create the specified table at the target database. I have tried the PreparedStatement interface but could not actually get to the method that would serve the purpose.

I have tried this code :

public void tableCreation()
{
BufferedReader br = new BufferedReader(new(InputStreamReader(System.in)));
System.out.println("Enter Table's Name:");
String tablename = br.readLine();
System.out.println("Enter filed name :");
String field1 = br.readLine();
System.out.println("Enter Filed Size");
int i = Integer.parseInt(br.readLine());

// and so on for the remaining fields.
//Can i use PreparedStatement object for that?
// How would my query to the database look like?

PreparedStatement pst = con.createStatement();
pst.execute(query);
}

Would highly appreciate your help.

Omar Salem
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Omar,
You'll have to build it up in Java: "select " + fieldName + " from " + table.

Binding variables (the question marks) don't work for table or field names.
 
reply
    Bookmark Topic Watch Topic
  • New Topic