944,129 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 26488
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
Dec 7th, 2005
0

Please help with JSP mysql update query

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cacorat is offline Offline
4 posts
since Dec 2005
Dec 7th, 2005
0

Re: Please help with JSP mysql update query

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cacorat is offline Offline
4 posts
since Dec 2005
Dec 7th, 2005
0

Re: Please help with JSP mysql update query

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cacorat is offline Offline
4 posts
since Dec 2005
Dec 7th, 2005
0

Re: Please help with JSP mysql update query

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cacorat is offline Offline
4 posts
since Dec 2005
Jan 10th, 2006
0

Re: Please help with JSP mysql update query

Quote 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')
Reputation Points: 10
Solved Threads: 0
Newbie Poster
brambo71c is offline Offline
1 posts
since Jan 2006
Jan 22nd, 2006
0

Re: Please help with JSP mysql update query

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
yup
Reputation Points: 10
Solved Threads: 1
Newbie Poster
yup is offline Offline
7 posts
since Jan 2006
May 23rd, 2008
0

Re: Please help with JSP mysql update query

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>");
%>
Reputation Points: 28
Solved Threads: 106
Banned
dnanetwork is offline Offline
633 posts
since May 2008
May 23rd, 2008
0

Re: Please help with JSP mysql update query

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
May 24th, 2008
0

Re: Please help with JSP mysql update query

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
weasy is offline Offline
2 posts
since May 2008
May 24th, 2008
0

Re: Please help with JSP mysql update query

Click to Expand / Collapse  Quote originally posted by weasy ...
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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Add month in date
Next Thread in JSP Forum Timeline: HTTP Status 405 - HTTP method GET is not supported by this URL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC