insert data into database with jsp -
I have to include data in a DB with a form, I did this code but now it does not work. I want to know where the problem is in this code
this is the code
the connection con = null;
try {string driveName = "com.mysql.jdbc.Driver"; Class.forName (driveName) .newInstance (); } Hold (java.lang.ClassNotFoundException e) {System.err.print ("ClassNotFoundException:"); System.err.println (e.getMessage ()); } Try {con = DriverManager.getConnection ("jdbc: mysql: // localhost: 3306 / onlinequiz", "root", "root"); Description Details = con.createStatement (); // ind id = integer Parasent (request.getParameter ("T1")); Int quizid = integer. Parseint (request.getParameter ("quizid")); take string 2 = Request .getParameter ("question_type"); String course = request.getParameter ("course"); String level = request.getParameter ("level");
int duration = integer Parasont (request.getParameter ("period"));
string title = request.getParameter ("title"); String description = request.getParameter ("description");
Enter the statement.executeUpdate ("Quiz, Inclination, Description, Quiz, Question_type, Duration, Level) values ('+ + + +' '' '+ Title +', '' + Description + '', '' + QuizID + '', '' + take2 + '', '' + duration + '', '' + + level + ''));
%> & Lt;% statement.close (); } Hold (exception e) {out.println ("exception:" + e.getMessage ()); } // Execute the statements, even if the exception is {}% & gt; I tried and edited this code and its work, I made some changes, I want that the user chooses according to the type of question which is a drop down box Or the truth is wrong, if the statement that forwards the user to my liking, then I should write.
Does the above code throw an exception, is it executed? If so, can you copy / paste the exception message in the post?
In addition, you should not add direct user input to your inserted query, it is prone to SQL injection attacks. Instead, use the prepared statements and consider using the appropriate Model-View-Control architecture using the Data Access Layer for all database transactions.
Comments
Post a Comment