eclipse在运行的时候不能在数据库添加内容

我在做添加内容的时候提示SQL语句输入错误,但是我查不出来哪里有错,求各位大佬的帮助!!
一下分别为代码和错误提示。(非图片部分为dealadd.jsp的代码)
代码:图片说明

```<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Insert title here


<%
String username = null;
String sno = null;
String password = null;
String birthday = null;
String tel = null;
String character = null;
username = request.getParameter("username");
sno = request.getParameter("sno");
password = request.getParameter("password");
birthday = request.getParameter("birthday");
tel = request.getParameter("tel");
character = request.getParameter("character");
     try{
         //将前一个页面提交来的数据写入数据库
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/mydatabase";
        Connection con = DriverManager.getConnection(url,"root","root");
        Statement stat = con.createStatement();
        stat.executeUpdate("insert into user (sno,username,password,character,birthday,tel) values ('"
                +sno+"','"+username+"','"+password+"','"+character+"','"+birthday+"','"+tel+"')");
        stat.close();
        stat.close();
        out.print("添加成功!");
    }catch(Exception ex){
        ex.printStackTrace();
    } 
%>



错误提示:
com.mysql.jdbc.exceptions.jdbc4.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 'character,birthday,tel) values ('null','null','null','null','null','null')' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485)
    at org.apache.jsp.dealadd_jsp._jspService(dealadd_jsp.java:115)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
com.mysql.jdbc.exceptions.jdbc4.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 'character,birthday,tel) values ('003','123','123','123','123','2334234')' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485)
    at org.apache.jsp.dealadd_jsp._jspService(dealadd_jsp.java:115)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

1个回答

错提示中有这部分内容

   check the manual that corresponds to your MySQL server version for the right syntax to use near 'character,birthday,tel) values ('null','null','null','null','null','null')' at line 1

对应你的SQL为

  stat.executeUpdate("insert into user (sno,username,password,character,birthday,tel) values ('"
                +sno+"','"+username+"','"+password+"','"+character+"','"+birthday+"','"+tel+"')");

SQL 中插入的参数是从

String username = null;
String sno = null;
String password = null;
String birthday = null;
String tel = null;
String character = null;
username = request.getParameter("username");
sno = request.getParameter("sno");
password = request.getParameter("password");
birthday = request.getParameter("birthday");
tel = request.getParameter("tel");
character = request.getParameter("character");

这部分代码中取出的参数,若你的request中对应的参数为null的话, 那么赋值失败,SQL 会报出这种错误,建议检查request 内部的数据是否正常

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
eclipse 运行时添加数据库内容报错

我在sql语句上报错,但是我初步出来哪里有问题,麻烦各位大佬帮忙! ![图片说明](https://img-ask.csdn.net/upload/202003/09/1583767924_444054.jpg)![图片说明](https://img-ask.csdn.net/upload/202003/09/1583767936_75404.jpg) 错误代码: com.mysql.jdbc.exceptions.jdbc4.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 'character,birthday,tel) values ('null','null','null','null','null','null')' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.Util.getInstance(Util.java:381) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485) at org.apache.jsp.dealadd_jsp._jspService(dealadd_jsp.java:115) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) com.mysql.jdbc.exceptions.jdbc4.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 'character,birthday,tel) values ('003','123','123','123','123','2334234')' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.Util.getInstance(Util.java:381) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485) at org.apache.jsp.dealadd_jsp._jspService(dealadd_jsp.java:115) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)

eclipse中jsp能连接数据库但是访问不了数据库里面的表!!!

代码如下: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="java.sql.*" %> <!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>Insert title here</title> </head> <body> <center> <br><br><br> <h2>使用jdbc访问sqlserver2008数据库</h2> <hr> <table width=800 border=2 align="center"> <tr> <th>学号</th> <th>班级</th> <th>姓名</th> <th>密码</th> </tr> <% try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); }catch(Exception q) { q.printStackTrace(); } String dbUrl = "jdbc:sqlserver://USER-20151124PC:50493;DatabaseName=Xk1"; String user="sa"; String pwd="sa"; try { Connection conn=DriverManager.getConnection(dbUrl,user,pwd); Statement stmt=conn.createStatement(); String sql="select * from Name"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()){ %> <tr> <td><%=rs.getString("Id")%></td> <td><%=rs.getString("Name") %></td> <td><%=rs.getString("Age")%></td> <td><%=rs.getString("Sex") %></td> </tr> <% } rs.close(); stmt.close(); conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } %> </table> <hr> </center> </body> </html> 然后访问是这样![图片说明](https://img-ask.csdn.net/upload/201604/27/1461749419_558910.png) 帮忙纠正一下!!

eclipse连接数据库出错

问题如下: eclipse能加载数据库驱动,却不能连接 ![图片说明](https://img-ask.csdn.net/upload/201910/31/1572530581_866255.png) eclipse、mysql环境配置都没问题 数据库版本是8.0以上 驱动程序mysql-connector-java-8.0.16放的位置也没错 mysql可以用控制台操作 mysql服务已启动 用户名是root 密码123456 ``` C:\Users\HP>mysql -uroot -p Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 23 Server version: 8.0.17 MySQL Community Server - GPL ``` 创建好了database student ``` mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | register | | student | | sys | +--------------------+ 6 rows in set (0.00 sec) ``` 搞了半天头都大了,这块搞不定下面的javaweb根本没法学,求大佬指导。

eclipse-j2ee中导入项目不能在servers上运行

导入了一个文件,但是不显示run as rervers?也不能运行啊

eclipse能连接 sqlserver2000 数据库反馈值却为null

高位高手: 实际是能连接数据库的 但ConnectDb.ConnectDb() 值 始终是null 请指点! package ConnectDataBase; import java.sql.*; public class ConnectDb { public static Connection con; public static Connection ConnectDb(){ String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=pubs"; String userName = "sa"; String userPwd = ""; Connection dbConn = null; try { Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL, userName, userPwd); System.out.println("Connection Successful!"); } catch (Exception e) { System.out.println("Connection error!"); e.printStackTrace(); } return dbConn; } } <%@ page import="ConnectDataBase.ConnectDb" %> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% if (ConnectDb.ConnectDb()!=null) {out.println("连接数据库成功!");} else {out.println("连接数据库error!");} %> 显示连接数据库error!实际是能连接数据库的 但ConnectDb.ConnectDb() 值 始终是null

后台 注册页面数据插入的实现,正常运行不报错但数据库中插不进数据

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ page import="com.two.dao.*"%> <%@ page import="java.util.*"%> <% request.setCharacterEncoding("UTF-8"); String action = request.getParameter("action"); if(action != null && action.trim().equals("register")) { String register_name = request.getParameter("register_name"); String register_password = request.getParameter("register_password"); String register_password2 = request.getParameter("register_password2"); String register_phone = request.getParameter("register_phone"); String register_address = request.getParameter("register_address"); String register_email = request.getParameter("register_email"); RegisterDao u = new RegisterDao(); u.setRegister_name(register_name); u.setRegister_password(register_password); u.setRegister_password2(register_password2); u.setRegister_phone(register_phone); u.setRegister_address(register_address); u.setRegister_email(register_email); out.println("注册成功!恭喜!"); return; } %>public class JDBC { private static final String URL = "jdbc:mysql://localhost:3306/myceshi"; private static final String USER = "root"; private static final String PASSWORD = "root"; static { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println("加载Mysql数据库驱动失败!"); } } public void setRegister_email(String register_email) { this.register_email = register_email; } public void save() { Connection conn = DB.getConn(); String sql = "insert into register values (null,?, ?, ?, ?, ?, ?)"; PreparedStatement pstmt = DB.prepare(conn, sql); try { pstmt.setString(1, register_name ); pstmt.setString(2, register_password); pstmt.setString(3, register_password2); pstmt.setString(4, register_phone); pstmt.setString(5, register_address); pstmt.setString(6, register_email); pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { DB.close(pstmt); DB.close(conn); } } ``` ``` ``` ``` ``` ``` }![图片说明](https://img-ask.csdn.net/upload/201705/10/1494408179_305481.png) ``` ```

用eclipse做一个简单的注册模块,数据传不到数据库中

用eclipse做一个简单的注册模块,输入用户名和密码,选择性别,按提交,将数据写如数据库,运行时出现的错误: HTTP Status 500 - javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'UserName' cannot be null 有时错误提示还会变成: HTTP Status 500 - An exception occurred processing JSP page /registerProcess.jsp at line 7 代码是相同的,为什么会有不同的错误提示呢? 我的第七行代码: org.apache.jasper.JasperException: An exception occurred processing JSP page /registerProcess.jsp at line 7 4: <jsp:useBean id="userInfo" class="chapa.UserInfo" scope="session"></jsp:useBean> 5: <jsp:useBean id="database" class="chapa.Database" scope="page"></jsp:useBean> 6: <% 7: database.register(userInfo); 8: response.sendRedirect("welcome.jsp"); 9: %> 我理解是将前面输入的信息存入数据库的意思。 database类和register方法: public class Database { private static String url = "jdbc:mysql://localhost:3306/chapA"; private static String driver = "com.mysql.jdbc.Driver"; private static String userName = "root"; private static String password = "root"; private Connection connection; //打开数据库连接 public Connection getConnection() throws ClassNotFoundException,SQLException { Class.forName(driver); connection = DriverManager.getConnection(url, userName, password); return connection; } //关闭数据库连接 public void closeConnection() throws SQLException { if(connection !=null && !connection.isClosed()) connection.close(); connection = null; } //注册 public void register(UserInfo userInfo) throws SQLException,ClassNotFoundException { String sql = "insert into userinfo values(?,?,?);"; PreparedStatement ps = getConnection().prepareStatement(sql); int i = 1; ps.setString(i++, userInfo.getUserName()); ps.setString(i++, userInfo.getPassword()); ps.setString(i++, userInfo.getSex()); ps.executeUpdate(); closeConnection(); } } 是不是我写的方法有问题?还是数据库没有连接好?我按书上一步一步做的,查了好几遍都没错呀。请各位大神指正啊!! 初学者,表达相当不专业,表达不清的地方请巨巨指出!需要看哪部分代码也请告诉我一下,我再往上贴。。 非常感谢!!!!跪谢!!! ![图片说明](https://img-ask.csdn.net/upload/201507/06/1436190289_684291.jpg)

java在eclipse上能连接sql2012数据库,为什么打包成jar后就不行了?

java在eclipse上能连接sql2012,用Fat jar打包成jar后就不行了。为什么?之前没下载过什么sqljdbc.jar、sqljdbc4.jar的驱动也能连接的呀。最后在网上下载了驱动一同打包后还是没能连接成功。classpath什么的也不会配置。求教!已附上错误提示图

关于eclipse中将数据导入数据库的中文乱码问题。急求解决

我也在网上找过相关问题,在eclipse中也改了三个地方的字符编码,以及数据库管理软件中的编码。但是提交到数据库后 ,还是有乱码,全部都是问号,图如下: ![图片说明](https://img-ask.csdn.net/upload/201511/18/1447820842_758232.jpg) ![图片说明](https://img-ask.csdn.net/upload/201511/18/1447820858_292119.jpg) ![图片说明](https://img-ask.csdn.net/upload/201511/18/1447820868_566753.png) ![图片说明](https://img-ask.csdn.net/upload/201511/18/1447820781_548727.png) 以及代码: ``` <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.PreparedStatement"%> <%@page import="java.sql.Connection"%> <%@ page language="java" contentType="text/html; charset=UTF-8" 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>Insert title here</title> </head> <body> <% String name = (String) request.getParameter("username"); String password = (String) request.getParameter("password"); String repassword = (String) request.getParameter("repassword"); if(!password.equals(repassword)){ response.sendRedirect("error.jsp"); } String sex = (String) request.getParameter("sex"); String work = (String) request.getParameter("work"); String[] love = (String[]) request.getParameterValues("love"); String show = (String) request.getParameter("show"); String strLove = ""; for (int i = 0; i < love.length; i++) { if(strLove.trim().equals("")){ strLove = strLove + "'" + love[i].toString() + "'"; }else{ strLove=strLove+","+"'"+love[i].toString()+"'"; } } if(strLove.trim().substring(0,strLove.trim().length()).equals(",")){ strLove=strLove.trim().substring(0,strLove.trim().length()-1); } Connection conn=null; PreparedStatement stmt=null; String mname=new String(name.getBytes("ISO-8859-1"), "UTF-8"); String mpassword=new String(password.getBytes("ISO-8859-1"), "UTF-8"); String msex=new String(sex.getBytes("ISO-8859-1"), "UTF-8"); String mwork=new String(work.getBytes("ISO-8859-1"), "UTF-8"); String mlove=new String(strLove.getBytes("ISO-8859-1"), "UTF-8"); String mshow=new String(show.getBytes("ISO-8859-1"), "UTF-8"); try{ Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","123456"); stmt=conn.prepareStatement("insert into student(username,password,sex,work,love,shows) values(?,?,?,?,?,?)"); stmt.setString(1, mname); stmt.setString(2, mpassword); stmt.setString(3, msex); stmt.setString(4, mwork); stmt.setString(5, mlove); stmt.setString(6, mshow); stmt.execute(); }catch(Exception e){ e.printStackTrace(); } //response.sendRedirect("success.jsp"); %> </body> </html> ``` 请大神帮我解决下这个问题吧,头都要炸了。。。。。 本人在学习初期,懂得不多,不喜勿喷。。。

eclipse连接数据库是总是显示404是为什么

![![图片说明](https://img-ask.csdn.net/upload/201810/18/1539836557_540860.png)图片说明](https://img-ask.csdn.net/upload/201810/18/1539836538_722615.png)

求大神帮帮忙,eclipse开发中,用jdbc连接数据库,加载驱动运行报错

这是我加载驱动的代码: String sql="select * from parkinfo where city='"+myCity+"'"; Random random=new Random(); try { Class.forName("org.gjt.mm.mysql.Driver"); conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/park", "root", "root"); //PreparedStatement pst=conn.prepareStatement(sql); //pst.setString(1, myCity); //ResultSet rs=pst.executeQuery(); Statement st=conn.createStatement(); ResultSet rs=st.executeQuery(sql); int remain=random.nextInt(rs.getInt("space")); List<Info> myCityInfo=new ArrayList<Info>(); if(rs.next()){ myCityInfo.add(new Info(rs.getDouble("latitude"), rs.getDouble("longitude"), R.drawable.my_car, rs.getString("name"), rs.getString("address"), remain, rs.getInt("charge"), rs.getInt("reserve"))); } addOverlays(myCityInfo); st.close(); conn.close(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } 已经为MySQL包(jar)添加路径了,运行时控制台console出现下面情况,看不到的错误啊 UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000) at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472) at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406) at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388) at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251) at com.android.dx.command.dexer.Main.processClass(Main.java:665) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634) at com.android.dx.command.dexer.Main.access$600(Main.java:78) at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:596) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264) at com.android.dx.command.dexer.Main.run(Main.java:230) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:188) at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:786) at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:597) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:321) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:396) at org.eclipse.core.internal.resources.Project$1.run(Project.java:618) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344) at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597) at org.eclipse.core.internal.resources.Project.build(Project.java:124) at com.android.ide.eclipse.adt.internal.project.ProjectHelper.doFullIncrementalDebugBuild(ProjectHelper.java:1143) at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:155) at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:855) at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:704) at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1047) at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) ...while parsing com/mysql/jdbc/JDBC42CallableStatement.class [2016-07-29 16:52:00 -MySQL] Dx 1 error; aborting [2016-07-29 16:52:00 -MySQL] Conversion to Dalvik format failed with error 1

eclipse不连接数据库 模拟简易学生管理系统

这个功能 怎么实现学生注册:学号+姓名+年龄 同一个学号只能注册一次

我用java程序向数据库中添加一条记录,提示成功 在数据库中并没有

我用java程序向本地的sql server 2000中添加一条记录,java控制台提示成功![图片说明](https://img-ask.csdn.net/upload/201702/04/1486204123_720929.png)但是用查询分析器select之后并没有这条记录。![图片说明](https://img-ask.csdn.net/upload/201702/04/1486204135_406053.png)把这个sql语句直接输入在查询分析器中就可以显示出来,问一下大神们这是怎么回事 连接用的是jdbc-odbc的方式! 以下是代码 ``` /* * 演示使用jdbc-odbc桥连方式操作数据库luoyedb1(emp,dept) * 1.配置数据源 */ package com.test1; import java.sql.*; public class Test1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Connection ct=null; Statement sm=null; try{ // 1.加载驱动(作用是把需要的驱动程序加入内存) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // 2.得到连接(指定连接到哪个数据源,用户名和密码) //如果配置数据源的时候,选择的是windows NT验证,则不需要输入用户名和密码 ct=DriverManager.getConnection("jdbc:odbc:mytest","sa","07247857"); // 3.创建Statement或者preparedStatement //Statement主要是发送sql语句 通道 sm=ct.createStatement(); // 4.执行(crud,创建数据库,备份。。) //添加一条数据dept表 //executeUpdate可以执行添加删除修改 int i=sm.executeUpdate("insert into dept values('80','aaa','bbb')"); if(i==1) { System.out.println("添加成功!"); }else{ System.out.println("添加失败!"); } }catch(Exception e){ e.printStackTrace(); }finally{ //关闭资源!!! //关闭顺序是,谁后创建则先关闭 try { //为了程序健壮 if(sm!=null) { sm.close(); } if(ct!=null) { ct.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } ```

eclipse不显示汉字

<div class="post-text" itemprop="text"> <p>From Eclipse, I am running a PHP script which has an embedded call to a cloud mySQL stored procedure.</p> <p>mySQL Workbench can store and display Chinese characters correctly.</p> <p>Eclipse returns the dataset correctly in English, but Chinese characters cannot be displayed properly.</p> <p>This is what I 've tried so far:</p> <ol> <li><p>In mySQL, I created the table with this specification:<br><code>ENGINE=INNODB AUTO_INCREMENT= 2468 CHARACTER SET utf8 COLLATE utf8_general_ci;</code></p></li> <li><p>In the PHP script, I specified the header like this:<br><code>header("Content-type:application/json; charset=utf-8");</code></p></li> <li>The response from executing sproc is json_encoded, like this:<br><code>echo json_encode(array("db_response"=&gt;$response));</code></li> <li>And in Eclipse, I've set the preference to UTF-8, like this:<br>in <em>Window &gt; Preferences: General &gt; Workspace</em> set file encoding to <em>Other UTF-8</em></li> </ol> <p>Chinese characters are displayed like this: ??????(??)????</p> <p>Can anyone point me in the right direction, please?</p> <p>Is there some other fonts I need to download and install in Eclipse? If so, which one?</p> </div>

eclipse运行动态web项目,我输入的URL运行报错,是我哪里弄错了

http://localhost:8080/MyTest/SaleEntry.jsp?itemID=1&numItems=3&discountCode=4 HTTP Status 500 - /SaleEntry.jsp (line: 17, column: 66) Attribute value request.getParameter("itemID") is quoted with " which must be escaped when used within the value ![图片说明](https://img-ask.csdn.net/upload/201702/08/1486562495_437747.jpg) ![图片说明](https://img-ask.csdn.net/upload/201702/08/1486562514_64158.jpg) ![图片说明](https://img-ask.csdn.net/upload/201702/08/1486562524_324605.png) ![图片说明](https://img-ask.csdn.net/upload/201702/08/1486562532_970212.jpg)

java的sql复制在数据库里能执行,但是运行还是报错啊

![图片说明](https://img-ask.csdn.net/upload/201807/11/1531295730_859866.png) 这个sql在数据库是能执行的但是还是报错

eclipse运行是报错500

eclipse运行是报错500 ``` <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*" %> <%@ page import="java.util.*" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% String username2=""; String password2=""; username2=request.getParameter("username1"); password2=request.getParameter("password1"); String sql="insert into user(username,password) values(?,?)"; Class.forName("com.mysql.jdbc.Driver"); String url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8"; Connection connection = DriverManager.getConnection(url, "root", "123456"); PreparedStatement pstmt=connection.prepareStatement(sql); pstmt.setString(1,username2); pstmt.setString(2,password2); try{ int n=pstmt.executeUpdate(); if(n==1){%> 恭喜你,添加成功!<br> <%} else{%> 添加失败,请重试。<br> <%} }catch(Exception e){ %>已重复添加,请重试<br> <a href="Add.jsp">点击此处返回</a> <%; } if(pstmt!=null){pstmt.close();} if(connection!=null){connection.close();} %> </body> </html>![图片说明](https://img-ask.csdn.net/upload/202006/22/1592823975_389844.png) ```前一天还可以用,第二天开机运行就错了,数据库已经链接了的,账号密码也没有错误d

启动tomcat的时候自动在mysql数据库创建对应的表,谁知道啊。。。。。。。

大家知道怎么在eclipse离写好类和hbm.xml映射文件后,启动tomcat自动在mysql数据库创建相对应的表吗,我跟着视频写老是报错 <property name="mappingLocations" value="com/atguigu/ssh/entities/*.hbm.xml"></property>就这句话错

安卓项目导入问题,通过服务器端连接数据库

我将别人的一个完整的app项目导入自己电脑里,其中将.sql文件导入了mysql数据库 将服务器端导入了MyEclipse,将客户端文件导入了eclipse里,运行avd模拟器不能够连接到sql数据库里的内容,这是为什么?,是不是还需要修改什么呢?

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

立方体线框模型透视投影 (计算机图形学实验)

计算机图形学实验 立方体线框模型透视投影 的可执行文件,亲测可运行,若需报告可以联系我,期待和各位交流

2019 AI开发者大会

2019 AI开发者大会

组成原理课程设计(实现机器数的真值还原等功能)

实现机器数的真值还原(定点小数)、定点小数的单符号位补码加减运算、定点小数的补码乘法运算和浮点数的加减运算。

C/C++跨平台研发从基础到高阶实战系列套餐

一 专题从基础的C语言核心到c++ 和stl完成基础强化; 二 再到数据结构,设计模式完成专业计算机技能强化; 三 通过跨平台网络编程,linux编程,qt界面编程,mfc编程,windows编程,c++与lua联合编程来完成应用强化 四 最后通过基于ffmpeg的音视频播放器,直播推流,屏幕录像,

MFC一站式终极全套课程包

该套餐共包含从C小白到C++到MFC的全部课程,整套学下来绝对成为一名C++大牛!!!

软件测试2小时入门

软件测试2小时入门

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

计算机图形学-球的光照模型课程设计

计算机图形学-球的光照模型,有代码完美运行,有课程设计书

Linux常用命令大全(非常全!!!)

Linux常用命令大全(非常全!!!) 最近都在和Linux打交道,感觉还不错。我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较短小但却功能强大。我将我了解到的命令列举一下,仅供大家参考: 系统信息 arch 显示机器的处理器架构 uname -m 显示机器的处理器架构 uname -r 显示正在使用的内核版本 d...

因为看了这些书,我大二就拿了华为Offer

四年了,四年,你知道大学这四年我怎么过的么?

深度学习原理+项目实战+算法详解+主流框架(套餐)

深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

fakeLocation13.5.1.zip

fakeLocation13.5.1 虚拟定位 ios13.5.1的最新驱动下载,iPhone/iPad免越狱虚拟定位工具Location-cleaned驱动已更新

UnityLicence

UnityLicence

Python可以这样学(第一季:Python内功修炼)

Python可以这样学(第一季:Python内功修炼)

Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

土豆浏览器

土豆浏览器可以用来看各种搞笑、电影、电视剧视频

【数据结构与算法综合实验】欢乐连连看(C++ & MFC)案例

这是武汉理工大学计算机学院数据结构与算法综合实验课程的第三次项目:欢乐连连看(C++ & MFC)迭代开发代码。运行环境:VS2017。已经实现功能:开始游戏、消子、判断胜负、提示、重排、计时、帮助。

php+mysql学生成绩管理系统

学生成绩管理系统,分三个模块:学生,教师和管理员。 管理员模块:负责学生、老师信息的增删改;发布课程信息的增删改,以便让学生选课;审核老师提交的学生成绩并且打印成绩存档;按照课号查询每个课号的学生成绩

多功能数字钟.zip

利用数字电子计数知识设计并制作的数字电子钟(含multisim仿真),该数字钟具有显示星期、24小时制时间、闹铃、整点报时、时间校准功能

推荐24个国外黄色网站欣赏

在中国清朝,明黄色的衣服只有皇子才有资格穿,慢慢的黄色在中国就成了高贵的颜色。在人们的色彩印象中,黄色也表现为暂停。所以当你的网页设计采用黄色的时候,会让人们在你的网页前停留。 黄色,就像橙色和红色,黄色也是一个暖色。它有大自然、阳光、春天的涵义,而且通常被认为是一个快乐和有希望的色彩。黄色是所有色相中最能发光的颜色,给人轻快,透明,辉煌,充满希望的色彩印象。 黄色是一个高可见的色...

u-boot-2015.07.tar.bz2

uboot-2015-07最新代码,喜欢的朋友请拿去

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

学生成绩管理系统(PHP + MYSQL)

做的是数据库课程设计,使用的php + MySQL,本来是黄金搭配也就没啥说的,推荐使用wamp服务器,里面有详细的使用说明,带有界面的啊!呵呵 不行的话,可以给我留言!

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

C++语言基础视频教程

C++语言基础视频教程

玩转Python-Python3基础入门

玩转Python-Python3基础入门

相关热词 c#怎么获得线程名 c# usb 采集器 c# sort() c#面对对象的三大特性 c# 打印 等比缩放 c#弹出右键菜单 c# 系统托盘图标 c# 键值对 键可以重复 c# 鼠标移上去提示 c#结构体定义
立即提问