unable to identify the table in specified database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PreethiGowri
    New Member
    • Oct 2012
    • 126

    unable to identify the table in specified database

    i have the following code which checks if the table exists in the database, if yes then inserts some values

    Code:
    String data = "%1:zetakalyam:arjun";
    if (data.startsWith("%1")) {
    String str = data;
    String[] cmd;
    String delimiter = "%|\\$|\\:|\\#";
    cmd = str.split(delimiter);
    System.out.println(cmd.length);
    for (int i = 0; i < cmd.length;i++) {
    System.out.println("cmd of " +i+ "=" +cmd[i]);
                       }
    Connection con = null;
    try{
     Class.forName("com.mysql.jdbc.Driver");
      String conURL = "jdbc:mysql://localhost/employee";
      con = DriverManager.getConnection(conURL, "root", "root");
      DatabaseMetaData dbm = con.getMetaData();
      ResultSet tables = dbm.getTables(null, null, "+cmd[2]+", null);
     if (tables.next()) { //if table exists
    Statement st = con.createStatement();
    String query = "insert into " + cmd[2] + " 
    (name,employee_id,date,logout) select 
    name,employee_id,curdate(),'0' from tbi where name = '" + cmd[3] + "'";
      ResultSet rs1 = st.executeQuery(query); 
                    }
    else{
                    
     System.out.println("table does not exists");
                  }
                  }
    catch(ClassNotFoundException | SQLException e){
                      
                  }

    i have a database called employee, which contains a table zetakalyam But, i get the result as table does not exists:(

    i have checked the database and it shows the table in its list
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    On line 17, I would check the value that you're passing because I don't think it's passing what you think it's passing.

    Comment

    • PreethiGowri
      New Member
      • Oct 2012
      • 126

      #3
      i'm not able to solve this, can you suggest me something

      Comment

      • PreethiGowri
        New Member
        • Oct 2012
        • 126

        #4
        i solved it,

        i had to write just cmd[2] instead of "+cmd[2]+"

        Comment

        Working...