Hello, I'm using Eclipse 3.3 and I use a model class HandlereplyModel.java to insert values to a mysql database using mysql5.0 server.When I run my application, I got duplicate values everytime I enter a record.
my java class is : import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class HandlereplyModel { public String insert(String fname, String lname, String Email, String phone) { /* Create string of connection url within specified format with machine name, port number and database name. Here machine name id localhost and database name is myfanclub. */ try { String url = "jdbc:mysql://localhost:3306/myfanclub"; /* myfanclub is my new database that contains my MemberDetails table */ // Load JBBC driver "com.mysql.jdbc.Driver" Class.forName("com.mysql.jdbc.Driver").newInstance(); /* create a connection to the database by using Connection interface and java.sql.DriverManager's getConnection( ) method */ Connection conn = DriverManager.getConnection(url,"root","root"); /* createStatement() is used for create statement object that is used for sending sql statements to the specified database. */ Statement st = conn.createStatement(); // sql query to insert values in the specified table st.executeUpdate("INSERT into MemberDetails (First_name, Last_Name, E_mail,Phone_num) VALUES ( '" + fname + "' , '" + lname + "' , '" + Email + "' , '" + phone + "' );" ); st.close(); conn.close(); } catch (Exception e) { return"Failure"; } return "Success";//// In Handlereply servlet we can check if the result of this function is success, and if it is, serve back the SuccesPage.jsp } } Please,advise...