java 连接oracle 出现一个问题,大家帮我看看啊! java.sql.SQLSyntaxErrorException: ORA-00917: 缺失逗
packagecom.hacker.base;//往oracle中插入数据importjava.io.IOException;importjava.io.PrintWri...
package com.hacker.base;
//往oracle中插入数据
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CL extends HttpServlet {
public CL() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Mysql mysql = new Mysql();
Connection con = null;
Statement stat = null;
int num = 0;
// int id = mysql.mid2();
PrintWriter out = response.getWriter();
String uname = request.getParameter("username");
String unick = request.getParameter("nick");
String upasswd = request.getParameter("passwd");
String urpasswd = request.getParameter("passwdconfim");
String uemail = request.getParameter("email");
System.out.println(uemail);
String str = "insert into users values("
+2+"',"+uname+"','"+unick+"','"+upasswd+"','"+urpasswd
+"','"+uemail+"')";
try {
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","zhangyong","123");
stat = con.createStatement();
System.out.println("0");
num = stat.executeUpdate(str);//经过测试,发现这句话没执行!!!!!!!!!!!!
System.out.println("1");
if(num == 1) {
out.println("<script language='javascript'>alert('注册成功')</script>");
} else {
out.println("<script language='javascript'>alert('注册失败')</script>");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if(stat != null) stat.close();
if(con != null) con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
public void init() throws ServletException {
// Put your code here
}
} 展开
//往oracle中插入数据
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CL extends HttpServlet {
public CL() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Mysql mysql = new Mysql();
Connection con = null;
Statement stat = null;
int num = 0;
// int id = mysql.mid2();
PrintWriter out = response.getWriter();
String uname = request.getParameter("username");
String unick = request.getParameter("nick");
String upasswd = request.getParameter("passwd");
String urpasswd = request.getParameter("passwdconfim");
String uemail = request.getParameter("email");
System.out.println(uemail);
String str = "insert into users values("
+2+"',"+uname+"','"+unick+"','"+upasswd+"','"+urpasswd
+"','"+uemail+"')";
try {
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","zhangyong","123");
stat = con.createStatement();
System.out.println("0");
num = stat.executeUpdate(str);//经过测试,发现这句话没执行!!!!!!!!!!!!
System.out.println("1");
if(num == 1) {
out.println("<script language='javascript'>alert('注册成功')</script>");
} else {
out.println("<script language='javascript'>alert('注册失败')</script>");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if(stat != null) stat.close();
if(con != null) con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
public void init() throws ServletException {
// Put your code here
}
} 展开
3个回答
展开全部
你的sql语句有个小错误
String str = "insert into users values("
+2+"',"+uname+"','"+unick+"','"+upasswd+"','"+urpasswd
+"','"+uemail+"')";
+2+"',"+uname+"'
这里你把uname左边的单引号写到逗号前面了
改为
String str = "insert into users values("
+2+", '"+uname+"','"+unick+"','"+upasswd+"','"+urpasswd
+"','"+uemail+"')"
还有问题HI我哈
String str = "insert into users values("
+2+"',"+uname+"','"+unick+"','"+upasswd+"','"+urpasswd
+"','"+uemail+"')";
+2+"',"+uname+"'
这里你把uname左边的单引号写到逗号前面了
改为
String str = "insert into users values("
+2+", '"+uname+"','"+unick+"','"+upasswd+"','"+urpasswd
+"','"+uemail+"')"
还有问题HI我哈
展开全部
显然你拼出来的SQL语句有错误,insert的那句话,println出来看看就知道了,users这个表总共几个列?都给值了吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你把错误贴出来看看,
把str也输出来看看执行的sql是什么样的
把str也输出来看看执行的sql是什么样的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询