Jsp database operation problems

Category: Web Develop
 
xiaye0106
2011-05-07 12:33:02

Sponsored Links
package dao;
import java.sql. *;

import beans.ShopBean;
import Connect.Dbconnection;
public class ShopDAO {
private ShopBean shop;

public ShopBean getShop () {
return shop;
}

public void setShop (ShopBean shop) {
this.shop = shop;
}

public boolean checkshop (ShopBean s) ; throws SQLException {
boolean flag = false;
Connection conn = Dbconnection.getconnection ();
String sql = "select isshopman from users where userid = '"+ s.getUserid () +"' ";
Statement st = null;
ResultSet rs = null;
try {
st = conn . createStatement ();
rs = st.executeQuery (sql);
while (rs.next ()) {
if (rs.getInt ("isshopman") == 0)
{
flag = true;
}
}

} catch (Exception e) {
System.out.println ("error");
}
finally
{
rs.close ();
st.close ();
conn.close ();
}
return ; flag;
}

public boolean addshop (ShopBean s) throws SQLException {
boolean flag = false;
if (checkshop ( s)) {
Connection conn = Dbconnection.getconnection ();
String sql = "insert into shop" + "(shopname, resume, userid ) "+" values ​​(?,?,?) ";
PreparedStatement ps = null;

try {
; ps = conn.prepareStatement (sql);
ps.setString (1, s.getShopname ());
ps.setString (2, s.getResume ());
ps.setInt (3, s.getUserid ());
; ps.executeUpdate (sql);
flag = true;
} catch (Exception e) {
e.printStackTrace ();;
}
finally
{
conn.close ();
}
}
return flag;
}
public static void ; main (String [] args) throws SQLException
{
ShopDAO dao = new ShopDAO ();
ShopBean s = new ShopBean ();
s.setResume ("sss");
s.setShopname ("wohao");
s.setUserid (21);
if (dao.addshop (s) ) {
System.out.println ("success");
}
}
}
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 ; '?,?,?)' at line 1
at com.mysql.jdbc.SQLError.createSQLException (SQLError.java: 1026)
at com.mysql.jdbc. SQLError.createSQLException (SQLError.java: 956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket (MysqlIO.java: 3515)
at com.mysql.jdbc.MysqlIO.checkErrorPacket (MysqlIO. java: 3447)
at com.mysql.jdbc.MysqlIO.sendCommand (MysqlIO.java: 1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect (MysqlIO.java: 2101)
at com.mysql.jdbc.ConnectionImpl.execSQL (ConnectionImpl.java: 2548)
at com.mysql.jdbc.StatementImpl.executeUpdate (StatementImpl.java: 1605)
at com. mysql.jdbc.StatementImpl.executeUpdate (StatementImpl.java: 1524)
at dao.ShopDAO.addshop (ShopDAO.java: 57)
at dao.ShopDAO.main (ShopDAO.java: 76)

expert to teach me

Sponsored Links

vic_apple
2011-05-07 12:51:36
insert into shop "+" (shopname, resume, userid) "+" values ​​(? ,?,?) ";

see your database if the corresponding parameter type, and length
btzf2005
2011-05-07 01:10:19
at dao.ShopDAO.addshop (ShopDAO.java: 57)
at dao.ShopDAO.main (ShopDAO.java: 76)
error in this,
a912214311
2011-05-07 01:19:03
insert into shop "+" (shopname, resume, userid) "+" values ​​(?,?,?)

sql problem (shopname, resume, userid) and values ​​less spaces between . . .
qq153767152
2011-05-07 01:21:56
is the problem. . . .
doedhardy
2011-05-07 01:27:02
you to print at your sql statement. . See there is no mistake. .
zql1984816
2011-05-07 01:43:08
small spaces
novery12
2011-05-07 01:54:25
sql syntax problem
first drug run sql print to the background, and how to perform under the database to see if I can not . Program no problem.
acedry
2011-05-07 02:05:08
sql problem
thespinningtop
2011-05-07 02:09:17
the table listed ..
ml1458601
2011-05-07 02:22:08
String sql = "insert into shop ; "+" (shopname, resume, userid) "+" where values ​​(?,?,?) "; is between double quotes and values ​​less spaces!
shengyin1225
2011-05-07 02:27:31
String sql = "insert into shop (shopname, resume, userid) values ​​(?,?,?)";

between the use of space separated!
you this shop table only insert these three field data! Other fields may be NULL? Primary key it? If you want to self-growth, then
insert into shop (id, shopname, resume, userid) values ​​(null,?,?,?)
cdutly
2011-05-07 02:44:21
this problem it is best to SQL print to the console, then the SQL statement into the database
replaced with a question mark and then the actual value in the next, see if you can succeed. . . .
chq117
2011-05-07 02:47:25
do not see what this abnormal sensation!
huangxiujian2007
2011-05-07 02:56:42
"insert into shop (shopname, resume, userid) values ​​(" +? + "," +? + "," +? + ") ";
try this line does not!
moyuzee
2011-05-07 03:04:56
problem that is not a space parameters matching
field names written on yet
shuiyueer24
2011-05-07 03:16:11

Support the landlord positive solution, After all, the console can guarantee your sql statement is no problem
guanchaogogo
2011-05-07 03:34:22
instead of spaces. Thank
chhb420181761
2011-05-07 03:49:16
I added a space available is still the same!
linlin1321
2011-05-07 04:00:14
Thank you, but not the problem
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.

Page 1 of 2    «»