Hi,
Instead of executeQuery(sql) you need to use executeUpdate(sql). For
further information please go through documentation on JDBC.
Regards,
Divakar
-----Original Message-----
From: kuttappan [mailto:[EMAIL PROTECTED]]
Sent: Saturday, March 24, 2001 11:29 AM
To: [EMAIL PROTECTED]
Subject: Cannot insert data into table
Hello all. This is a snippet from my JavaBean that I'm using to insert data
into MySql database.
The bean is working perfectly alright but I can't insert data into the user
table. Please help and do tell what I'm doing wrong here.
This is the code:
public String saveToDB() {
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
try {
cn = DriverManager.getConnection("jdbc:mysql://localhost/users");
try{
Statement st = cn.createStatement();
String sql = "insert into user Values('"+userName+"','"+password1+"')";
st.executeQuery(sql);
return "success";
}
catch(SQLException e){
return e.toString();
}
}
catch(SQLException e){
return e.toString();
}
}
catch(ClassNotFoundException e){
return e.toString();
}
catch(Exception e) {
return e.toString();
}
}
Thanks.
Rohit.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.237 / Virus Database: 115 - Release Date: 07/03/2001
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets