Go Back   AionSource.com > Everything Else > The Basement
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

The Basement Hardware and software nerds, unite! Who needs sunlight anyway?!

Reply
 
LinkBack Thread Tools Display Modes
Old 04-10-2008, 03:27 AM   #1 (permalink)
Daeva
 
Celestin's Avatar
 
Join Date: Feb 2007
Location: Formerly Isengard, Middle Earth.
Celestin is on a distinguished road


Looking for MySQL / JDBC expert

Yeah, I know a gaming forum isn't the best place to post this ( I'm posting in some other areas as well ), but my god, if you can help me, please do so.

I'm going to take a nap because I pretty much have to.

If you know how to perform an insert query into MySQL using JDBC, please help me! :O

This is what I have:
Code:
query = "insert into stars value(" +starId +", '" +firstName +"', '" +lastName +"', null, '" +url +"');";
System.out.println(query);
            
try {
   select = connection.createStatement();
   result = select.executeQuery(query);
} catch (SQLException e) {
   System.out.println("Error: I have no idea at all what this error indicates."
      +"n");
}
And this is the output:
Code:
Requested Id: 2
First name: Frank
Last name: Lee
Photo URL: www.url.com
insert into stars value(2, 'Frank', 'Lee', null, 'www.url.com');
Error: I have no idea at all what this error indicates.
The output is a copy paste of what happens when I run that part of my program. The blue is user input, everything else is system output.

The error that is being caught is a general SQL error, could really be anything like column count mismatch or something. Anything that causes the MySQL db backend to freak out. I'm also too lazy to come up with a solution or create a better error message.

I have checks on all the inserted fields to ensure they are of the right type. As far as I can tell, the insert query itself is correct so I think it has something to do with the code, specifically the select.executeQuery(query) part. Please halp!
__________________
"Those who dance are considered insane by those who can't hear the music." - George Carlin

"And I would feel no pain / And never be without pleasure / Ever / Again / And if the rain stops and everythings dry / She would cry / Just so I could drink the tears from her eyes / She'll teach me how to fly / Even cushion my fall / If my engines ever stall / And I plummet from the sky / But she would keep me high." - Lupe Fiasco

Last edited by Celestin; 04-10-2008 at 03:30 AM..
Celestin is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-10-2008, 05:34 AM   #2 (permalink)
Daeva
 
arkhaal's Avatar
 
Join Date: Nov 2007
Location: fromage \o/
arkhaal is on a distinguished road

Race: Undecided

It's because your request is an "INSERT", so you have to use "executeUpdate" instead of "executeQuery" in the part :

Code:
try {
   select = connection.createStatement();
   result = select.executeQuery(query);
} catch (SQLException e) {
   System.out.println("Error: I have no idea at all what this error indicates."
      +"n");
}
should be :
Code:
try {
   select = connection.createStatement();
   result = select.executeUpdate(query);
} catch (SQLException e) {
   System.out.println("Error: I have no idea at all what this error indicates."
      +"n");
}
and you can modity your error msg to :
Code:
System.err.println("error : " + e.getMessage());
soo.... final code is :
Code:
try {
   select = connection.createStatement();
   result = select.executeUpdate(query);
} catch (SQLException e) {
   System.err.println("error : " + e.getMessage());
}
__________________

Last edited by arkhaal; 04-10-2008 at 05:41 AM..
arkhaal is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Top Aion Aion Top

All times are GMT -5. The time now is 09:45 AM.