Problem with CREATE TABLE statement
843859Jul 23 2007 — edited Jul 23 2007Here is the code which tries to create a table using prepare statement
the code compiles and i get the error:
Error on Creating Table :java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''dept_no' varchar(25) NOT NULL,'dept_name' varchar(25) NULL,PRIMARY KEY('dept_no' at line 1"
Am enclosing my code here. Plz let me know where does i fail?
public int create(String table_name,String column1,String column2){
System.out.println("Starting!!!create");
int n=0;
try{
connect();
stmt=con.prepareStatement("CREATE TABLE "+table_name+" ( ? varchar(25) NOT NULL,? varchar(25) NULL,PRIMARY KEY(?))");
stmt.setString(1,column1);
stmt.setString(2,column2);
stmt.setString(3,column1);
n=stmt.executeUpdate();
}catch(Exception e){
System.out.println("Error on Creating Table :"+e);
}
return n;
}
Message was edited by:
Abhi_The_Software_Nerd