每当程序运行时,我的程序都无法为表生成一个新名称,因此它没有被创建。这是我的代码:-
package org.java.myfirstapp;
import java.sql.*;
public class ConnectForm {
public void createFormData(String name,String num){
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/formdata", "root", null);
try{
int no=1,no1 = 0;
do{Statement st=con.createStatement();
no1=no;
int x;
x= st.executeUpdate("create table form"+no+" (Product varchar(20),Fields varchar(20))");
if(x==0){
st.executeUpdate("insert into form"+no+" values ('"+name+"','"+num+"')");
}
else {
no++;}
}while(no1<no);
}
catch(SQLException e1){
System.err.println("Error code:"+e1.getMessage());}
}
catch(Exception e1){
e1.printStackTrace();
}
}
}