Wednesday, 14 August 2013

Database Insertion error due to query

Database Insertion error due to query

I have a new database.I want to insert manual values and picking table
name from a database. But it shows an error.The following code i use.My
row values are first one is a String and following are
Integers(here=fcltyname is the only String)
connection = (Connection) dbSource.getConnection();
String qry = "SELECT studentName From batcha ";
System.out.println(fcltyName);
stmt = (PreparedStatement) connection.prepareStatement(qry);
rs = stmt.executeQuery();
while (rs.next()) {
String check=new String(rs.getString(("studentName")));
String student = check.replaceAll("\\s","");
Class.forName("com.mysql.jdbc.Driver");
connection = (Connection)
DriverManager.getConnection(DB_URL_table, USER, PASS);
String sql1 = "INSERT IGNORE INTO "+student+"
(fcltyName,CommunicationOral,Communicationwritten,Leadership,AnalyticalAbilities,Interpersonalskills,DecisionMakingSkills,SelfConfidence,Creativity,Punctualityregularity,GeneralAwareness,Commitment,HardWork)VALUES("+fcltyName+",0,0,0,0,0,0,0,0,0,0,0,0)";
newStmt=(PreparedStatement)
connection.prepareStatement(sql1);
newStmt.executeUpdate(sql1);
newStmt.close();
Error
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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
'0,0,0,0,0,0,0,0,0,0,0,0)' at line 1

No comments:

Post a Comment