String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
stmt.executeUpdate(sql);
20 个解决方案
#1
String sql="INSERT INTO user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
#2
已经试过了的,不行哦,再帮我一下/
Syntax error or access violation, message from server: "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 'user(username,userpass,usertitle,usercontent) values('null','nu"……
Syntax error or access violation, message from server: "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 'user(username,userpass,usertitle,usercontent) values('null','nu"……
#3
我用的是JSP语言来做的。
#4
String sql="insert into user values(null,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
#5
在ORACLE里面就可以了,用个seqence或者触发器就OK了
#6
还是不行的。
String sql="insert into user values(null,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
String sql="insert into user values(null,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
#7
Syntax error or access violation, message from server: "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 'user(username,userpass,usertitle,usercontent) values('null','nu"……
你看看报错信息,你的那些值都没有取过来,都是‘null’的值啊
那怎么可能更新得了呢?
你确信你的那些username的值都不是null??
print出来看看
你看看报错信息,你的那些值都没有取过来,都是‘null’的值啊
那怎么可能更新得了呢?
你确信你的那些username的值都不是null??
print出来看看
#8
就是麽!print 一下
#9
auto_increment的字段不用处理啊,SQL语句里面空出来,不用管那个字段,自己会生成的。
#10
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%//@ page import="javax.servlet.*" %>
<%//@ page import="javax.servlet.http.*" %>
<%!//字符串处理常用方法
public String getString(String s)
{
if (s==null) s="";
try {byte a[]=s.getBytes("ISO-8859-1");
s=new String(a);
}
catch(Exception e)
{
}
return s;
}
%>
<%
if (request.getParameter("b1") != null)
{
out.print("现在要添加数据吗???<br>");
String uuname=getString(request.getParameter("username"));
String uupass=getString(request.getParameter("userpass"));
String uutitle=getString(request.getParameter("usertitle"));
String uucontent=getString(request.getParameter("usercontent"));
}
else
{
out.print ("当前,不需要添加数据!!!");
}
%>
<%
String username=null;String userpass=null;String usertitle=null;String usercontent=null;
String user="root";String password="root";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/info?useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="insert into user(username,userpass,usertitle,usercontent) values('username','userpass','usertitle','usercontent')";
//String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
stmt.executeUpdate(sql);
//response.sendRedirect("book.jsp");
%>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%//@ page import="javax.servlet.*" %>
<%//@ page import="javax.servlet.http.*" %>
<%!//字符串处理常用方法
public String getString(String s)
{
if (s==null) s="";
try {byte a[]=s.getBytes("ISO-8859-1");
s=new String(a);
}
catch(Exception e)
{
}
return s;
}
%>
<%
if (request.getParameter("b1") != null)
{
out.print("现在要添加数据吗???<br>");
String uuname=getString(request.getParameter("username"));
String uupass=getString(request.getParameter("userpass"));
String uutitle=getString(request.getParameter("usertitle"));
String uucontent=getString(request.getParameter("usercontent"));
}
else
{
out.print ("当前,不需要添加数据!!!");
}
%>
<%
String username=null;String userpass=null;String usertitle=null;String usercontent=null;
String user="root";String password="root";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/info?useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="insert into user(username,userpass,usertitle,usercontent) values('username','userpass','usertitle','usercontent')";
//String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
stmt.executeUpdate(sql);
//response.sendRedirect("book.jsp");
%>
#11
大家帮我看看上面这个页面,添加数据的时候总不会成功。
#12
是因为""用的不对
#13
这样改
String sql="insert into user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','+"usertitle+"','+"usercontent+"')";
String sql="insert into user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','+"usertitle+"','+"usercontent+"')";
#14
String sql="insert into user(username,userpass,usertitle,usercontent) values('username','userpass','usertitle','usercontent')";
//String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
换成我上面那句试试
//String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
换成我上面那句试试
#15
现在将问题简化到:
String sql="insert into user(username,userpass,usertitle,usercontent) values(1,2,3,4)";
结果还是不行的。
String sql="insert into user(username,userpass,usertitle,usercontent) values(1,2,3,4)";
结果还是不行的。
#16
String sql="insert into user(username,userpass,usertitle,usercontent) values('1','2','3','4')";
晕。要注意
auto字段不用管。
其它字段要注意如果是数字就无''
如果是字付串或是text要有''
晕。要注意
auto字段不用管。
其它字段要注意如果是数字就无''
如果是字付串或是text要有''
#17
好像写得不对吧!!
这样也不行麽???
String sql="insert into user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','+"usertitle+"','+"usercontent+"')";
这样也不行麽???
String sql="insert into user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','+"usertitle+"','+"usercontent+"')";
#18
对于自动编号的字段我们是不需要写的啊!
如果 表 t :ID:autoinc,Name:Varchar(20)
insert into t(Name) values('xxx');
如果 表 t :ID:autoinc,Name:Varchar(20)
insert into t(Name) values('xxx');
#19
最后终于搞定了,感谢各位兄弟:::
String sql="INSERT INTO user (id, username, userpass, usertitle, usercontent, datetime) VALUES(NULL,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"','555')";
我的邮件:www@gyit.com
我的QQ:9684040
String sql="INSERT INTO user (id, username, userpass, usertitle, usercontent, datetime) VALUES(NULL,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"','555')";
我的邮件:www@gyit.com
我的QQ:9684040
#20
其实既然 id 自动编号,就不用具体写出来了啊
String sql="INSERT INTO user ( username, userpass, usertitle, usercontent, datetime) VALUES('"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"','555')";
就可以了
String sql="INSERT INTO user ( username, userpass, usertitle, usercontent, datetime) VALUES('"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"','555')";
就可以了
#21
#1
String sql="INSERT INTO user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
#2
已经试过了的,不行哦,再帮我一下/
Syntax error or access violation, message from server: "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 'user(username,userpass,usertitle,usercontent) values('null','nu"……
Syntax error or access violation, message from server: "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 'user(username,userpass,usertitle,usercontent) values('null','nu"……
#3
我用的是JSP语言来做的。
#4
String sql="insert into user values(null,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
#5
在ORACLE里面就可以了,用个seqence或者触发器就OK了
#6
还是不行的。
String sql="insert into user values(null,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
String sql="insert into user values(null,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
#7
Syntax error or access violation, message from server: "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 'user(username,userpass,usertitle,usercontent) values('null','nu"……
你看看报错信息,你的那些值都没有取过来,都是‘null’的值啊
那怎么可能更新得了呢?
你确信你的那些username的值都不是null??
print出来看看
你看看报错信息,你的那些值都没有取过来,都是‘null’的值啊
那怎么可能更新得了呢?
你确信你的那些username的值都不是null??
print出来看看
#8
就是麽!print 一下
#9
auto_increment的字段不用处理啊,SQL语句里面空出来,不用管那个字段,自己会生成的。
#10
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%//@ page import="javax.servlet.*" %>
<%//@ page import="javax.servlet.http.*" %>
<%!//字符串处理常用方法
public String getString(String s)
{
if (s==null) s="";
try {byte a[]=s.getBytes("ISO-8859-1");
s=new String(a);
}
catch(Exception e)
{
}
return s;
}
%>
<%
if (request.getParameter("b1") != null)
{
out.print("现在要添加数据吗???<br>");
String uuname=getString(request.getParameter("username"));
String uupass=getString(request.getParameter("userpass"));
String uutitle=getString(request.getParameter("usertitle"));
String uucontent=getString(request.getParameter("usercontent"));
}
else
{
out.print ("当前,不需要添加数据!!!");
}
%>
<%
String username=null;String userpass=null;String usertitle=null;String usercontent=null;
String user="root";String password="root";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/info?useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="insert into user(username,userpass,usertitle,usercontent) values('username','userpass','usertitle','usercontent')";
//String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
stmt.executeUpdate(sql);
//response.sendRedirect("book.jsp");
%>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%//@ page import="javax.servlet.*" %>
<%//@ page import="javax.servlet.http.*" %>
<%!//字符串处理常用方法
public String getString(String s)
{
if (s==null) s="";
try {byte a[]=s.getBytes("ISO-8859-1");
s=new String(a);
}
catch(Exception e)
{
}
return s;
}
%>
<%
if (request.getParameter("b1") != null)
{
out.print("现在要添加数据吗???<br>");
String uuname=getString(request.getParameter("username"));
String uupass=getString(request.getParameter("userpass"));
String uutitle=getString(request.getParameter("usertitle"));
String uucontent=getString(request.getParameter("usercontent"));
}
else
{
out.print ("当前,不需要添加数据!!!");
}
%>
<%
String username=null;String userpass=null;String usertitle=null;String usercontent=null;
String user="root";String password="root";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/info?useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="insert into user(username,userpass,usertitle,usercontent) values('username','userpass','usertitle','usercontent')";
//String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
stmt.executeUpdate(sql);
//response.sendRedirect("book.jsp");
%>
#11
大家帮我看看上面这个页面,添加数据的时候总不会成功。
#12
是因为""用的不对
#13
这样改
String sql="insert into user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','+"usertitle+"','+"usercontent+"')";
String sql="insert into user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','+"usertitle+"','+"usercontent+"')";
#14
String sql="insert into user(username,userpass,usertitle,usercontent) values('username','userpass','usertitle','usercontent')";
//String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
换成我上面那句试试
//String sql="INSERT INTO user values"+"("+"'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"')";
换成我上面那句试试
#15
现在将问题简化到:
String sql="insert into user(username,userpass,usertitle,usercontent) values(1,2,3,4)";
结果还是不行的。
String sql="insert into user(username,userpass,usertitle,usercontent) values(1,2,3,4)";
结果还是不行的。
#16
String sql="insert into user(username,userpass,usertitle,usercontent) values('1','2','3','4')";
晕。要注意
auto字段不用管。
其它字段要注意如果是数字就无''
如果是字付串或是text要有''
晕。要注意
auto字段不用管。
其它字段要注意如果是数字就无''
如果是字付串或是text要有''
#17
好像写得不对吧!!
这样也不行麽???
String sql="insert into user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','+"usertitle+"','+"usercontent+"')";
这样也不行麽???
String sql="insert into user(username,userpass,usertitle,usercontent) values('"+username+"','"+userpass+"','+"usertitle+"','+"usercontent+"')";
#18
对于自动编号的字段我们是不需要写的啊!
如果 表 t :ID:autoinc,Name:Varchar(20)
insert into t(Name) values('xxx');
如果 表 t :ID:autoinc,Name:Varchar(20)
insert into t(Name) values('xxx');
#19
最后终于搞定了,感谢各位兄弟:::
String sql="INSERT INTO user (id, username, userpass, usertitle, usercontent, datetime) VALUES(NULL,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"','555')";
我的邮件:www@gyit.com
我的QQ:9684040
String sql="INSERT INTO user (id, username, userpass, usertitle, usercontent, datetime) VALUES(NULL,'"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"','555')";
我的邮件:www@gyit.com
我的QQ:9684040
#20
其实既然 id 自动编号,就不用具体写出来了啊
String sql="INSERT INTO user ( username, userpass, usertitle, usercontent, datetime) VALUES('"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"','555')";
就可以了
String sql="INSERT INTO user ( username, userpass, usertitle, usercontent, datetime) VALUES('"+username+"','"+userpass+"','"+usertitle+"','"+usercontent+"','555')";
就可以了