User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 391,944 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,902 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 12604 | Replies: 13
Reply
Join Date: Dec 2005
Posts: 4
Reputation: cacorat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cacorat cacorat is offline Offline
Newbie Poster

Help Please help with JSP mysql update query

  #1  
Dec 7th, 2005
I keep getting an error where the symbol cannot be resolved and the arrow pointing to where i have written statement.ExcecuteUpdate
Am not able to insert any data into my database, can anyone see where i may have gone wrong. thanx
heres the code:

<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>

<%
String connectionURL = "jdbc:mysql://localhost:3306/learningtest";
Connection connection = null;
Statement statement = null;
int UQ=0;
%>

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Submit Question</title>
</head>
<body>

<h1>Submit Question</h1>

<%
String questionin = request.getParameter("questionin");
String answerin = request.getParameter("answerin");
String subjectin = request.getParameter("subjectin");%>

<td align="right">Question:</td>
<td><%=questionin %></td>
<br>
<td align="right">Answer:</td>
<td><%=answerin %></td>
<br>
<td align="right">Subject:</td>
<td><%=subjectin %></td>


<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "", "");
statement = connection.createStatement();

UQ=statement.executeUpdate("INSERT INTO questions" +
"(qid, question, answer, subject)" + "VALUES (" ," + questionin + "," + answerin + "," + subjectin)" );


out.println("Question Added Success");
statement.close();


%>


</body>
</html>


p.s. the excecutequery works fine i can read from the database so there isnt anyprobs with the connection string
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 4
Reputation: cacorat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cacorat cacorat is offline Offline
Newbie Poster

Re: Please help with JSP mysql update query

  #2  
Dec 7th, 2005
this is the error message
: method executeUpdate(java.lang.String, java.lang.String) not found in interface java.sql.Statement

it seems there is a declaration problem. I am using the com.mysql, and the function seems to be present
Reply With Quote  
Join Date: Dec 2005
Posts: 4
Reputation: cacorat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cacorat cacorat is offline Offline
Newbie Poster

Re: Please help with JSP mysql update query

  #3  
Dec 7th, 2005
sorry this is the correct code:
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>

<%
String connectionURL = "jdbc:mysql://localhost:3306/learningtest";
Connection connection = null;
Statement statement = null;

%>

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Submit Question</title>
</head>
<body>

<h1>Submit Question</h1>

<%
String questionin = request.getParameter("questionin");
String answerin = request.getParameter("answerin");
String subjectin = request.getParameter("subjectin");%>

<td align="right">Question:</td>
<td><%=questionin %></td>
<br>
<td align="right">Answer:</td>
<td><%=answerin %></td>
<br>
<td align="right">Subject:</td>
<td><%=subjectin %></td>


<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "", "");
statement = connection.createStatement();


int UQ=statement.executeUpdate("insert into questions (qid, question, answer, subject) values ('," + questionin + "," + answerin + "," + subjectin + ")");


if (UQ==1)
{
out.println("Question Added Success");
}
else
{
out.println("Addition failed");
}

statement.close();


%>


</body>
</html>

it runs except i get an sql error where the syntax is incorrect at the values being inserted...pls help
Reply With Quote  
Join Date: Dec 2005
Posts: 4
Reputation: cacorat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cacorat cacorat is offline Offline
Newbie Poster

Re: Please help with JSP mysql update query

  #4  
Dec 7th, 2005
the error message:
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '',ooo,ppp,Chemistry)' at line 1
Reply With Quote  
Join Date: Jan 2006
Posts: 1
Reputation: brambo71c is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
brambo71c brambo71c is offline Offline
Newbie Poster

Solution Re: Please help with JSP mysql update query

  #5  
Jan 10th, 2006
Originally Posted by cacorat
the error message:
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '',ooo,ppp,Chemistry)' at line 1

The problem is in the query brackets: ('" + blabla + "','" + blabla + "','" + blabla + "')" letting the output like ('xxx','yyy','zzz')
Reply With Quote  
Join Date: Jan 2006
Posts: 7
Reputation: yup is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
yup yup is offline Offline
Newbie Poster

Re: Please help with JSP mysql update query

  #6  
Jan 21st, 2006
Hi,
I think your Html missing some part. Could you please clarify that what is your form doing? Get the question + answer + subject from user... then update to database?

kind regards,
yup
Reply With Quote  
Join Date: May 2008
Posts: 2
Reputation: dnanetwork is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dnanetwork dnanetwork is offline Offline
Newbie Poster

Re: Please help with JSP mysql update query

  #7  
May 23rd, 2008
In the following examples, please substitute your information where the following data is referenced:

<server>: enter the MySQL server that you are assigned to, for example, mysql4.safesecureweb.com
<username>: enter the username provided for your database
<password>: enter the password provided for your database
<database>: enter the database name provided for your database
<DSN>: enter the DSN name (ColdFusion only)
PHP
<?php
$link = mysql_connect('<server>', '<username>', '<password>');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db(<database>);
?>

ColdFusion
<CFQUERY Name="test" DATASOURCE="<DSN>" USERNAME="<username>" PASSWORD="<password>">
</CFQUERY>

Perl
#!/usr/bin/perl

use DBI;

$db = DBI->connect("dbi:mysql:<database>","<username>","<password>")
or die("Couldn't connect");

$db->disconnect;

JSP
<%@ page import="java.sql.*" %>
<%@ page import="com.mysql.jdbc.Driver" %>

<%!
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn;
conn = DriverManager.getConnection(
"jdbc:mysql://<server>/<database>?user=<username>&password=<password>");
%>
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 191
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Please help with JSP mysql update query

  #8  
May 23rd, 2008
Kid, check the dates on threads you're replying to. This one was resolved well over 2 years ago.

But do tell, is it a new sport somewhere to create forum accounts just to post nonsense to age old threads?
I've been seeing it a lot lately.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: May 2008
Posts: 2
Reputation: weasy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
weasy's Avatar
weasy weasy is offline Offline
Newbie Poster

Re: Please help with JSP mysql update query

  #9  
May 24th, 2008
Javascript is amazing, I didn't think you could touch mysql with it!
Everyone kept telling me to use php with my js to get into sql.
HAHA I feel like a million bucks!
Thank you for your help and kindness,
Sincerely,
Your friendly Neighborhood
WEASY
Weasy.net
Reply With Quote  
Join Date: Feb 2006
Posts: 1,360
Reputation: masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough 
Rep Power: 8
Solved Threads: 117
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: Please help with JSP mysql update query

  #10  
May 24th, 2008
Originally Posted by weasy View Post
Javascript is amazing, I didn't think you could touch mysql with it!
Everyone kept telling me to use php with my js to get into sql.
HAHA I feel like a million bucks!


Except that this isn't JavaScript.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 8:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC