|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| The Basement Hardware and software nerds, unite! Who needs sunlight anyway?! |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Daeva
Join Date: Feb 2007
Location: Formerly Isengard, Middle Earth.
![]() |
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");
}
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 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.. |
|
|
|
|
|
#2 (permalink) |
|
Daeva
Join Date: Nov 2007
Location: fromage \o/
![]() 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");
}
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");
}
Code:
System.err.println("error : " + e.getMessage());
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.. |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
All times are GMT -5. The time now is 09:45 AM.











Linear Mode
