InterviewSolution
Saved Bookmarks
| 1. |
How to create a table dynamically from a JDBC application? |
|
Answer» We can dynamically create a table by using the FOLLOWING code: //import sectionimport java.sql.*;import java.io.*;public class CreateTableEx{ public static void main(String[] args)throws Exception { //create an objet of buffered reader BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //load and register the driver Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); //ESTABLISH a connection Connection con = DriverManager.getConnection(“jdbc:odbc:nag”,”system”,”naveen”); //create a statement object Statement ST = con.createStatement(); //receive dynamic input as a table name System.out.println(“Enter table name”); String tablename = br.readLine(); //execute SQL query St.executeUpdate("create table"+tablename+"(empno number,EMPNAME varchar2(10),empsalary number,empaddress varchar2(20))"); System.out.println(“Successfully CREATED the table”); //close the connection con.close(); }} |
|