Lunarpages Web Hosting Forum

Author Topic: Problem with INSERT INTO using mySql called by a servlet  (Read 1030 times)

Offline dfp1294

  • Newbie
  • *
  • Posts: 2
Problem with INSERT INTO using mySql called by a servlet
« on: October 25, 2003, 02:24:30 PM »
Hi
Currently I have had no problems connecting to the database and calling the data using SELECT.  

However, now that I am trying to use a servlet to get information from the form (which it is doing) and insert the data into the database, I am getting error messages saying either permission is denied or there is a syntax error in my code.  I am using:

INSERT INTO database_name.loginName.tablename (field name1, field name2, etc) VALUES (TT1,TT2, etc)

Do you have any advice?

Thanks

Offline Decompile

  • Intergalactic Cowboy
  • *****
  • Posts: 65
More Info ...
« Reply #1 on: November 11, 2003, 07:22:57 PM »
Can you paste the exact error hear ....

Offline Decompile

  • Intergalactic Cowboy
  • *****
  • Posts: 65
Problem with INSERT INTO using mySql called by a servlet
« Reply #2 on: December 14, 2003, 11:47:31 AM »
I'm using Prepared statments and currently have had no problems at all from my JSP's or my Servlet's .. Here's a copy of a basic INSERT i use ...

PreparedStatement ps = con.prepareStatement("INSERT INTO table_name (field_1,field_2) VALUES (?,?)");

ps.setString(1,variable_1);
ps.setString(2,variable_2);   
ps.executeUpdate();


This has never failed me, and I have much larger and complex INSERT's I use ....


 Assuming both these fields are type VARCHAR, this should work perfectly as well ....

INSERT INTO table_name (field_1,field_2) VALUES ("info","more info")

Offline airly

  • Newbie
  • *
  • Posts: 1
Problem with INSERT INTO using mySql called by a servlet
« Reply #3 on: December 30, 2004, 01:51:25 AM »
Could you post the error code ? you can get the error code when u used sqle.getMessage();
the error code will look something like this .... 1064, 1052 ...blahblahblah

Offline GMTurner

  • Berserker Poster
  • *****
  • Posts: 7479
    • Turner's Lounge
Re: Problem with INSERT INTO using mySql called by a servlet
« Reply #4 on: December 30, 2004, 05:48:13 AM »
Quote from: dfp1294
INSERT INTO database_name.loginName.tablename (field name1, field name2, etc) VALUES (TT1,TT2, etc)


Don't think you need to have the loginName in there... database_name.tablename (or just tablename) should work...
The above information may or may not reflect current policy, opinions, or views since it was likely made almost 10 years ago.