i have the following code which checks if the table exists in the database, if yes then inserts some values
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
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
Comment