Servlet链接数据库不成功

图片说明

这里是service.xml的配置部分

    <Resource name="jdbc/webdb" auth="Container"
                type="javax.sql.DataSource"
                driverClassName="com.mysql.jdbc.Driver"
                url="jdbc:mysql://http://127.0.0.1:3306/webdb?characterEncoding=utf-8"
                username="root"
                password=""
                maxActive="200"
                maxIdle="50"
                maxWait="3000"
    />

2个回答

如果密码没有问题的话,就是“//http:”,url没有必要写这个吧

url去掉 //heep: 试试

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
servlet连接mysql数据库问题
本人初学web组件,很多基础不会,望各位大神不要鄙视~~~~ -----login.java---- package com.tsinghua; import javax.servlet.http.*; import java.io.*; public class Login extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res){ //业务逻辑 try{ //接受用户名和密码 String u=req.getParameter("usrename"); String p=req.getParameter("passwd"); //中文乱码 res.setContentType("text/html;charset=gbk"); PrintWriter pw=res.getWriter(); pw.println("<html>"); pw.println("<body>"); pw.println("<form action=logincl method=post>"); pw.println("用户名:<input type=text name=username><br>"); pw.println("密码:<input type=password name=passwd><br>"); pw.println("<input type=submit value=Login><br>"); pw.println("</form>"); pw.println("</body>"); pw.println("</html>"); } catch(Exception ex){ ex.printStackTrace(); } } public void doPost(HttpServletRequest req,HttpServletResponse res){ this.doGet(req,res); } } ----loginCl.java---------- package com.tsinghua; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class LoginCl extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res){ Connection ct=null; Statement sm=null; ResultSet rs=null; String host="127.0.0.1:3306"; try{ String u=req.getParameter("username"); String p=req.getParameter("passwd"); PrintWriter pw=res.getWriter(); Class.forName("com.mysql.jdbc.Driver"); ct=DriverManager.getConnection("jdbc:mysql://"+host+"/login","root","2535663"); sm=ct.createStatement(); rs=sm.executeQuery("select top 1 * from users where username='"+u+"'and passwd='"+p+"'"); pw.println("连接成功!"); if(rs.next()){ //合法 res.sendRedirect("welcome"); }else{ //不合法 res.sendRedirect("login"); } HttpSession hs=req.getSession(true); hs.setMaxInactiveInterval(30); hs.setAttribute("uname",u); } catch(SQLException e) { e.printStackTrace(); } catch(ClassNotFoundException e) { e.printStackTrace(); } catch(Exception ex){ ex.printStackTrace(); } finally{ try { if(rs!=null){ rs.close(); } if(sm!=null){ sm.close(); } if(ct!=null){ ct.close(); } }catch (Exception ex) { ex.printStackTrace(); } } } public void doPost(HttpServletRequest req,HttpServletResponse res){ this.doGet(req,res); } } ------wel.java------- package com.tsinghua; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class wel extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res){ Connection ct=null; Statement sm=null; ResultSet rs=null; String host="127.0.0.1:3306"; try{ String u=req.getParameter("username"); String p=req.getParameter("passwd"); //从session中得到用户名 HttpSession hs=req.getSession(true); String myName=(String)hs.getAttribute("uname"); String name=""; String passwd=""; if(myName==null){ res.sendRedirect("login"); return ; } //解决中文乱码 res.setCharacterEncoding("gbk"); PrintWriter pw=res.getWriter(); pw.println("<body bgcolor=#CED3FF>"); pw.println("<img src=imgs/1.GIF>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;欢迎您:"+myName+"<img src=imgs/me.gif><hr><center>"); pw.println("<h1>管理用户</h1>"); //做个超链接 pw.println("<br><a href=login>返回重新登录</a>"); }catch(Exception ex){ ex.printStackTrace(); } } public void doPost(HttpServletRequest req,HttpServletResponse res){ this.doGet(req,res); } } ----------------------------sql文件------------------------------------ drop database if exists login; create database login; use login; drop table if exists users; create table users ( username varchar(20), passwd varchar(20), email varchar(30), grade int); insert into users values ('admin','admin','admin@sohu.com',1); insert into users values ('shunping','shunping','shunping@sohu.com', 1); insert into users values ('tester1','tester1','tester1@sohu.com',5); insert into users values ('tester2','tester2','tester2@sohu.com',5); insert into users values ('tester3','tester3','tester3@sohu.com',5); insert into users values ('tester4','tester4','tester4@sohu.com',5); insert into users values ('tester5','tester5','tester5@sohu.com',5); insert into users values ('tester6','tester6','tester6@sohu.com',5); insert into users values ('tester7','tester7','tester7@sohu.com',5); insert into users values ('tester8','tester8','tester8@sohu.com',5); insert into users values ('tester9','tester9','tester9@sohu.com',5); insert into users values('tester10','tester10','tester10@sohu.com',5); insert into users values('tester11','tester11','tester11@sohu.com',5); insert into users values('tester12','tester12','tester12@sohu.com',5); insert into users values('tester13','tester13','tester13@sohu.com',5); insert into users values('tester14','tester14','tester14@sohu.com',5); select * from users; ------------------------------web.xml-------------------------------- <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1" metadata-complete="true"> <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <!-- JSPC servlet mappings start --> <servlet> <servlet-name>HelloGen</servlet-name> <servlet-class>com.tsinghua.HelloGen</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloGen</servlet-name> <url-pattern>/sp</url-pattern> </servlet-mapping> <servlet> <servlet-name>helloHttp</servlet-name> <servlet-class>com.tsinghua.helloHttp</servlet-class> </servlet> <servlet-mapping> <servlet-name>helloHttp</servlet-name> <url-pattern>/sh</url-pattern> </servlet-mapping> <servlet> <servlet-name>Login</servlet-name> <servlet-class>com.tsinghua.Login</servlet-class> </servlet> <servlet-mapping> <servlet-name>Login</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping> <servlet> <servlet-name>LoginCl</servlet-name> <servlet-class>com.tsinghua.LoginCl</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginCl</servlet-name> <url-pattern>/logincl</url-pattern> </servlet-mapping> <servlet> <servlet-name>wel</servlet-name> <servlet-class>com.tsinghua.wel</servlet-class> </servlet> <servlet-mapping> <servlet-name>wel</servlet-name> <url-pattern>/welcome</url-pattern> </servlet-mapping> <!-- JSPC servlet mappings end --> </web-app> -----------------------------------文件位置------------------------------------- ![](https://img-ask.csdn.net/upload/201610/05/1475664229_860957.png) ![](https://img-ask.csdn.net/upload/201610/05/1475664278_481068.png) mysql的jar包我也引了,然后这是sql文件位置。mysql运行没有问题。 然后文件我调试了,发现就是输入帐户名和密码后,离开登陆页面,进入登陆验证界面,进不去欢迎界面,调试后发现就是数据库连接不上。 各位大神帮帮忙,这个问题困扰很久了。。。
servlet的dopost中写了控制台输出,测试到不执行数据库工具类后的代码,也不报错,会输出数据访问成功,连接到这个servlet成功的。
``` request.setCharacterEncoding("UTF-8"); System.out.println("数据访问成功"); String sql="select * from employee"; DBUtil dbUtil = new DBUtil(); List<Employee> employeeList=new ArrayList<Employee>(); System.out.println("开始执行查询"); ```
Servlet登录验证写法,为啥不成功呀?
一直跳转到error页面,想各位看看是不是我代码有问题.. DBConn.java package dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class DBConn { public static Connection conn = null; /** * 得到数据库连接 */ public static Connection getConnection() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException { try { // 指定驱动程序 Class.forName("com.mysql.jdbc.Driver"); // 建立数据库连结 conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/system","root", "root"); return conn; } catch (Exception e) { // 如果连接过程出现异常,抛出异常信息 throw new SQLException("驱动错误或连接失败!"); } } /* * 释放连接 */ public static void closeConnection() throws Exception { if (conn != null && !conn.isClosed()) System.out.println("数据库关闭"); conn.close(); } } UserDao.java package dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import dao.User; import dao.DBConn; public class UserDao { private Connection conn = null; private PreparedStatement ps; public User login(String username, String password) throws Exception{ //List<User> users = new ArrayList<User>(); String sql = "select * from user where username = ? and password = ?"; //List<User> users=new ArrayList<User>(); conn=DBConn.getConnection(); ps=conn.prepareStatement(sql); ps.setString(1, username); ps.setString(2, password); ResultSet rs=ps.executeQuery(); while(rs.next()) { User user=new User(); user.setUsername(rs.getString("username"));//得到数据库中列 传入账号到User对象 user.setPassword(rs.getString("password")); //users.add(user); } return null; } } LoginServlet.java package servlet; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.mysql.jdbc.StringUtils; import dao.DBConn; import dao.User; import dao.UserDao; /** * Servlet implementation class LoginServlet */ @WebServlet("/LoginServlet") public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; DBConn db = new DBConn(); UserDao userDao = new UserDao(); User user = new User(); /** * @see HttpServlet#HttpServlet() */ public LoginServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out= response.getWriter(); String username=request.getParameter("username"); String password=request.getParameter("password"); UserDao userDao = new UserDao(); User user = null; try { user = userDao.login(username,password); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // 判断user是否为空 if(user != null){ // 转发到LoginSuccess.jsp页面 // getRequestDispatcher()是请求转发 request.getRequestDispatcher("register.jsp").forward(request, response); }else{ // 登录失败 request.getRequestDispatcher("error.jsp").forward(request, response); } } } login.jsp <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>登录页面</title> </head> <body> <form action="LoginServlet" method="post"> 用户名:<input type="text" name="username"> 密码:<input type="password" name="psd"> <input type="submit" value="登录"> </form> </body> </html> register.jsp <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> 成功! </body> </html> error.jsp <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> 失败! </body> </html>
java web 连接数据库的问题
程序突然就连不上数据库了,之前一直好好的,把登陆部分的代码贴上来,求大神给看看 jsp部分:<!DOCTYPE html> <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]--> <!--[if IE 7 ]> <html lang="en" class="no-js ie7 lt8"> <![endif]--> <!--[if IE 8 ]> <html lang="en" class="no-js ie8 lt8"> <![endif]--> <!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]--> <!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]--> <head> <meta charset="UTF-8" /> <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> --> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Login and Registration Form with HTML5 and CSS3" /> <meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" /> <meta name="author" content="Codrops" /> <link rel="shortcut icon" href="../favicon.ico"> <link rel="stylesheet" type="text/css" href="css/demo.css" /> <link rel="stylesheet" type="text/css" href="css/style.css" /> <link rel="stylesheet" type="text/css" href="css/animate-custom.css" /> </head> <body> <div class="container"> <!-- Codrops top bar --> <div class="codrops-top"> <div class="clr"></div> </div><!--/ Codrops top bar --> <header> <nav class="codrops-demos"> </nav> </header> <section> <div id="container_demo" > <!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4 --> <a class="hiddenanchor" id="toregister"></a> <a class="hiddenanchor" id="tologin"></a> <div id="wrapper"> <div id="login" class="animate form"> <form action="com.xx.servlet/LoginServlet" method="post"> <h1>Log in</h1> <p> <label for="username" class="uname" data-icon="u" > Your username </label> <input type="text" name="username" /> </p> <p> <label for="password" class="youpasswd" data-icon="p"> Your password </label> <input type="password" name="password" /> </p> <p class="keeplogin"> </p> <p class="login button"> <input type="submit" value="Login" /> </p> <p class="change_link"> Not a member yet ? <a href="register.jsp" class="to_register">Join us</a> </p> </div> </div> </div> </section> </div> </body> </html> servlet部分:package com.xx.servlet; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.naming.spi.DirStateFactory.Result; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.bbs.*; import com.mysql.jdbc.Driver; /** * Servlet implementation class LoginServlet */ @WebServlet("/LoginServlet") public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LoginServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response);// TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); request.setCharacterEncoding("utf-8"); String name = null;String level = null; Connection conn = null; Statement stmt=null; ResultSet res=null; boolean flag=false;//通过数据库匹配标识 String name_checked=null;//检查通过的用户名 try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } String URL="jdbc:mysql://localhost:3306/mybbs"; String USER="root"; String PASSWORD="5438027"; //1.加载驱动程序 try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e1) { System.out.println("加载驱动失败1");// TODO 自动生成的 catch 块 e1.printStackTrace(); } //2.获得数据库的链接 try { DriverManager.registerDriver(new Driver()); conn=DriverManager.getConnection(URL, USER, PASSWORD); } catch (SQLException e) { System.out.println("加载失败2");// TODO 自动生成的 catch 块 e.printStackTrace(); } String u=request.getParameter("username"); //从上级页面获得用户名 String p=request.getParameter("password"); //从上级页面获得密码 String sql="SELECT * FROM user WHERE userName IN('"+u+"') "+"AND passWord IN('"+p+"')"; System.out.println(sql);//执行上述sql语句 try { res=stmt.executeQuery(sql); } catch (SQLException e) { System.out.println("加载失败3");// TODO 自动生成的 catch 块 e.printStackTrace(); } try { if(true==res.next())//只有查询得到结果才可进入循环 { flag=true; name_checked=res.getString("name"); level=res.getString("level"); } } catch (SQLException e) { System.out.println("加载失败4");// TODO 自动生成的 catch 块 e.printStackTrace(); } if(true==flag)//登陆成功 { HttpSession session=request.getSession(); session.setAttribute("userlevel",level); session.setAttribute("name",name_checked); response.sendRedirect(request.getContextPath()+"/loginsuccess.jsp"); User me=new User(); } else//登陆失败 { response.sendRedirect(request.getContextPath()+"/login.jsp"); } } } 报错:HTTP Status 500 - type Exception report message description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.NullPointerException com.xx.servlet.LoginServlet.doPost(LoginServlet.java:99) javax.servlet.http.HttpServlet.service(HttpServlet.java:650) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.82 logs. Apache Tomcat/7.0.82 控制台:十月 26, 2017 1:10:55 上午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [LoginServlet] in context with path [/xxbbs] threw exception java.lang.NullPointerException at com.xx.servlet.LoginServlet.doPost(LoginServlet.java:99) at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) 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:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506) 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:962) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) 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(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:744) 不知道哪里出问题了,之前一直好好的,求大神帮我看看
Java web jdbc怎么连接数据库,要配置什么啊
代码都已经打完了,但是一直连接不成功,sqlserver数据库驱动也下下来了并放到buding path里了,sqlserver协议tcp/ip也更改了,数据库也用用户名密码登陆了,还差什么啊,求大神指教,下面是代码,都是网上的,应该没错。 package com.demo; import java.io.*; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import javax.servlet.*; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.*; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class register */ @WebServlet("/register.do") public class register extends HttpServlet { public Connection cn; public PreparedStatement ps; public ResultSet rs; //连接数据库 public void getCn() { String url="jdbc:microsoft:sqlserver://192.168.1.119:1433;DatabaseName=Web"; String driverpath="com.microsoft.jdbc.sqlserver.SQLServerDriver"; String name="sa"; String pwd="123456"; try{ Class.forName(driverpath); cn=DriverManager.getConnection(url,name,pwd); if(cn!=null) { System.out.println("ok"); cn.close(); } else System.out.println("数据库连接失败!"); }catch(Exception e) { e.printStackTrace(); } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ //得到post资源 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=gbk"); PrintWriter out=response.getWriter(); String name=request.getParameter("username"); String pwd=request.getParameter("password"); System.out.println(name); System.out.println(pwd); if(this.insert(name,pwd)==true) { out.println("注册成功"); } else out.println("注册失败"); out.flush(); out.close(); } //注册添加数据 public boolean insert(String name,String pwd) { getCn(); boolean b=false; String sql="insert into login values(?,?)"; try{ ps=cn.prepareStatement(sql); ps.setString(1, name); ps.setString(2, pwd); ps.execute(); b=true; }catch(Exception e) { e.printStackTrace(); }finally { try{ if(rs!=null) rs.close(); else if(ps!=null) ps.close(); else if(cn!=null) cn.close(); }catch(Exception e){} } return b; } }
servlet 怎么把数据库查到的东西传到HTML中
下面是我写的,不知道该怎么改了。。 package servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Date; public class Servlet1 extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 获取客户端发送的请求类型:GET/POST doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String responseBody = "Current request method is <B>:" + request.getMethod() + "</B> <br>" + new Date(); // 将所有HTML响应数据通过网络回发到客户端。 // 获取发送响应的PrintWriter对象 PrintWriter out = response.getWriter(); // 装在需要响应到客户端的响应数据 out.println(responseBody); try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); //注册JDBC驱动 Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=Stu_Man","sa","13361775956"); //链接数据库 System.out.println("连接成功!"); //如果连接成功,控制台输出“连接成功!” //查询数据 String str2= "select Course.couid,counam, coutimes, couroom, courtea from Course,Student,Score where stunam ='张三' and Student.stuid=Score.stuid and Score.couid=Course.couid"; Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(str2); response.setContentType("text/html;charset=utf-8"); while (rs.next()) { String a = rs.getString("couid"); String b = rs.getString("counam"); String c = rs.getString("coutimes"); String d = rs.getString("couroom"); String e = rs.getString("courtea"); out.print("<td><input type=\"checkbox\" name=\"id\" value=\""+a+"\"></td>"); out.print("<td>"+b+"</td>"); out.print("<td>"+c+"</td>"); out.print("<td>"+d+"</td>"); out.print("<td>"+e+"</td>"); out.print("</tr>"); } out.print("</table></center>"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); //插入数据 String str1 = "insert into Student values(107,'王九','男','95-05-02','技术4')"; Statement stm = con.createStatement(); int res= stm.executeUpdate(str1); if (res > 0) { System.out.println("数据已成功插入!"); } //删除数据 PreparedStatement p = null; try { String str3 = "delete from Student where stunam ='王' "; p = con.prepareStatement(str3); int row = p.executeUpdate(); System.out.println("成功删除了"+row+"行数据!"); } catch (SQLException sqlE) { sqlE.printStackTrace(); } if (rs != null) { con.close(); //释放资源 } } catch (SQLException e) { // e.printStackTrace(); System.out.println("数据执行错误!"); } catch(Exception e) { System.out.println("连接失败!"); } // 发送响应 out.close(); } }
Java WEB 连接数据库的登录界面失败?
连接数据库是成功的,但是输入用户名和密码后跳转到错误页面 有几段代码不太确定对不对,请帮忙看一看 //login.jsp ``` <form name="form1" method="post" action="manager.do?action=login"> ``` //struts-config.xml ``` <action name="managerForm" path="/manager" scope="request" type="com.action.Manager" validate="true"> <forward name="managerLoginok" path="/main.jsp" /> <forward name="error" path="/error.jsp" /> </action> ``` //Manager.java ``` package com.action; import org.apache.struts.action.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.actionForm.ManagerForm; import com.dao.ManagerDAO; import javax.servlet.http.HttpSession; public class Manager extends Action { private ManagerDAO managerDAO = null; public Manager() { this.managerDAO = new ManagerDAO(); } public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { String action = request.getParameter("action"); if (action == null || "".equals(action)) { return mapping.findForward("error"); } else if ("login".equals(action)) { return managerLogin(mapping, form, request, response); } request.setAttribute("error", "操作失败!"); return mapping.findForward("error"); } // 管理员身份验证 public ActionForward managerLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ManagerForm managerForm = (ManagerForm) form; //将接收到的表单信息强制转换成ActionForm类型 managerForm.setAd_name(managerForm.getAd_name()); managerForm.setAd_pwd(managerForm.getAd_pwd()); int ret = managerDAO.checkManager(managerForm); System.out.print("验证结果ret的值:" + ret); if (ret == 1) { //将登录到系统的管理员名称保存到session HttpSession session = request.getSession(); session.setAttribute("manager", managerForm.getAd_name()); return mapping.findForward("managerLoginok"); } else { request.setAttribute("error", "您输入的管理员名称或密码错误!"); return mapping.findForward("error"); } } } ``` //ConnDB.java ``` //执行查询语句 public ResultSet executeQuery(String sql) { try { conn=getConnection(); stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs=stmt.executeQuery(sql); } catch(SQLException ex){ System.err.println(ex.getMessage()); } return rs; } ``` //ManagerDAO.java ``` //管理员身份验证 public int checkManager(ManagerForm managerForm) { int flag = 0; ChStr chStr=new ChStr(); String sql = "SELECT * FROM Ad_info where ad_name='" + chStr.filterStr(managerForm.getAd_name()) + "'"; ResultSet rs = conn.executeQuery(sql); try { if (rs.next()) { String pwd = chStr.filterStr(managerForm.getAd_pwd()); //获取输入的密码并过滤输入字符串中的危险字符 if (pwd.equals(rs.getString(3))) { flag = 1; } else { flag = 0; } }else{ flag = 0; } } catch (SQLException ex) { flag = 0; }finally{ conn.close(); } return flag; } ``` 大概应该是这几段代码的原因,但是不清楚应该怎么修改,请帮忙看一下
jdbc连接数据库,可以加载驱动,数据库内却取不到值(NullPointException)?
我用两种途径连接数据库,一种是:<br> ![图片说明](https://img-ask.csdn.net/upload/201911/04/1572862039_634364.png)<br> 这一种应该没问题 <br><br> 但是在另一种途径遇到了以下问题:<br> ![图片说明](https://img-ask.csdn.net/upload/201911/04/1572862594_438226.jpg)<br><br> //以下是异常信息: 第一次提问,请问还需要什么信息orz <br><br> ----------------- 换了个电脑 代码进行修改之后 项目能够正常运行了 在原来的电脑上仍有以下报错: ```java 数据库驱动加载成功! Exceptionconn java.lang.NullPointerException findall failed at javax.xml.bind.DatatypeConverter.parseHexBinary(DatatypeConverter.java:310) at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4061) at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3157) at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:82) at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3121) at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7151) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2478) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2026) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1687) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1528) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:866) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:569) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228) at ch04.utils.BookUtils.getConnection(BookUtils.java:20) at ch04.dao.impl.BookDaoImpl.findByAll(BookDaoImpl.java:88) at ch04.service.impl.BookservicesImpl.findByAll(BookservicesImpl.java:38) at ch04.controller.BookAction.showall(BookAction.java:127) at ch04.controller.BookAction.doPost(BookAction.java:46) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:835) java.lang.NullPointerException at ch04.dao.impl.BookDaoImpl.findByAll(BookDaoImpl.java:92) at ch04.service.impl.BookservicesImpl.findByAll(BookservicesImpl.java:38) at ch04.controller.BookAction.showall(BookAction.java:127) at ch04.controller.BookAction.doPost(BookAction.java:46) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:835) [] ```
Java与数据库连接成功后
jsp输入框input,输入数据如何与servlet交互实现模糊查询
初学jsp遇到数据库连接处理问题
这个是注册插入数据代码,在网页中可以运行成功,说明我的数据库连接是没问题的 ``` <%String uid=request.getParameter("uid"); String pwd=request.getParameter("pwd"); Object[]paramss={uid,pwd}; String sqll="insert into tb_vip values(?,?)"; if(DBHelper.runupdatesql(sqll, paramss)) { out.print("已经成功注册"); } else out.print("服务器问题请与客服联系"); %> ``` 下面这段是判断数据库中用户名是否存在,不存在才可以用上面代码注册,但是运行后不管数据库中是否存在用户名,网页中只打印“注册失败,用户名不存在” ``` <% String uid=request.getParameter("uid"); String pwd=request.getParameter("pwd"); Object[] params={uid}; String sql ="select count(*)from tb_vip where userid=?"; Result result=DBHelper.runselectsql(sql, params); if(result.getRowCount()==0){ Object[]paramss={uid,pwd}; String sqll="insert into tb_vip values(?,?)"; if(DBHelper.runupdatesql(sqll, paramss)){ out.print("已经成功注册"); }else{out.print("服务器问题请与客服联系");}} else{ out.print("注册失败,用户名已存在"); } %> ``` 下面是java数据库处理代码部分 ``` package jspex; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import javax.servlet.jsp.jstl.sql.Result; import javax.servlet.jsp.jstl.sql.ResultSupport; public class DBHelper { private static final String className = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; private static final String url = "jdbc:sqlserver://localhost:1433;databasename=studentm"; private static final String uname = "sa"; private static final String upass = "c111111"; public static Connection getConn(){ Connection conn = null; try{ Class.forName(className); conn = DriverManager.getConnection(url,uname, upass); } catch(Exception e){ e.printStackTrace(); } return conn; } public static void closeConn(Connection conn){ try{ if(conn!=null){ conn.close(); } } catch(Exception e){ e.printStackTrace(); } } public static void closePstmt(PreparedStatement pstmt){ try{ if(pstmt!=null){ pstmt.close(); } } catch(Exception e){ e.printStackTrace(); } } public static void closeRs(ResultSet rs){ try{ if(rs!=null){ rs.close(); } } catch(Exception e){ e.printStackTrace(); } } public static boolean runupdatesql(String sql,Object[]params){ Connection con=null; PreparedStatement ps=null; try{ con=getConn(); ps=con.prepareStatement(sql); for(int i=0;i<params.length;i++){ ps.setObject(i+1, params[i]); } ps.executeUpdate(); return true; }catch(Exception e){ e.printStackTrace(); return false; } finally{ try{ ps.close(); con.close(); } catch(Exception e){ e.printStackTrace(); } } } public static Result runselectsql(String sql,Object[]params){ Connection con=null; PreparedStatement ps=null; ResultSet res=null; Result result=null; try{ con=getConn(); ps=con.prepareStatement(sql); for(int i=0;i<params.length;i++){ ps.setObject(i+1, params[i]); } res=ps.executeQuery(); result=ResultSupport.toResult(res); } catch(Exception e){ e.printStackTrace(); } finally{ try{ res.close(); ps.close(); con.close(); }catch(Exception e){ e.printStackTrace(); } } return result; } } ``` 下面是注册页面,我为了好找错误,还把相关js功能注释掉了 ``` <html> <head> <title>reg</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> #loginform{ width:300px; height:auto; } label{ width:60px; height:30px; text-align:left; font-size:14px; font-weight:hold; vertical-align:bottom; } .inpute{ width:160px; height:20px; } .row{ width:300px; height:30px; } </style> <script type="text/javascript"> function checkform(){ var name=document.getElementById("uid"); var pass=document.getElementById("pwd"); /*var rpass=document.getElementById("rpwd");*/ if(name.value.length<=0){ alert("用户名不能为空"); name.focus(); return false; } if(pass.value.length>=8){ alert("密码长度不对"); pass.focus(); return false; } /**if(pass!=rpass){ alert("密码不一致"); return false; }**/ return true; } </script> </head> <body> <div id="loginform"> <form onsubmit="return checkform();"action="doreg.jsp" method="post"> <div class="row"> <label for="uid">用户名: </label> <input name="uid" type="text" class="inpute" id="uid"> </div> <div class="row"> <label for="pwd">密码: </label> <input name="pwd" type="password" class="inpute" id="pwd"> </div> </div> <!-- <div class="row"> <label for="rpwd">确认密码:</label> <input name="rpwd" type="password" class="inpute" id="rpwd"> </div> --> <div class="row"> <input type="submit" value="注册"/><input type="reset" value="重新填写"/> </div> </form> </div> </body> </html> ``` 分析了很久,不知道出现了什么问题,希望大家可以帮帮我
数据库连接时总是空指针异常?测试表单信息无误,就是查询数据库时出错
java.lang.NullPointerException at com.Users.LoginServlet.doPost(LoginServlet.java:58) at javax.servlet.http.HttpServlet.service(HttpServlet.java:154) at javax.servlet.http.HttpServlet.service(HttpServlet.java:92) at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106) at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:173) at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:274) at com.caucho.server.port.TcpConnection.run(TcpConnection.java:514) at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:527) at com.caucho.util.ThreadPool.run(ThreadPool.java:449) at java.lang.Thread.run(Unknown Source) 源代码: package com.Users; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.Service.LoginService; /** * 登录控制层 : LoginServlet * 将用户个人信息保存到 Session范围内 * 根据status对页面进行分别显示 * @author daichen * */ public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; /* * 注入 LoginService 服务 */ private LoginService loginService; @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { doGet(req,res); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("GBK"); response.setCharacterEncoding("GBK"); User user = null; // 获取表单提交的登录信息 String userId = null; String password = null; userId = request.getParameter("userId"); password = request.getParameter("password"); // 先判断用户信息是否否为空 if(userId == null || "".equals(userId) || password == null || "".equals(password)) { // 用户信息有误 , 回到 login.jsp 页面 response.getWriter().println("<html><h3><font color='#f00'>对不起,你输入的信息有误 .请重新确认!</h3></font></html>"); return; } else { // 到数据表 user 中查找该用户 , 返回一个 User 对象 System.out.println(userId+" "+password); user = loginService.userLogin(userId,password); // 并对查询到的结果进行处理 if(user != null) { // 获取请求域的session对象 HttpSession session = request.getSession(); // 对三种权限分开添加到 Session 域中 if(user.getStatus() == 0){ session.setAttribute("geneUser", user); } if(user.getStatus() == 1){ session.setAttribute("admin", user); } if(user.getStatus() == 2){ session.setAttribute("superAdmin", user); } // 成功获取到用户信息 , 转到 index.jsp RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/index.jsp"); rd.forward(request, response); return; } else { // 查询没有该用户 , 转到 login.jsp response.getWriter().print("<h3><font color='#f00'>对不起,你还未注册用户 </h3></font>" + userId + "<h3><font color='#f00'>请先前去注册!</h3></font>"); RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/register.jsp"); rd.forward(request, response); return; } } } }
前端与数据库进行数据交互
你给的网站我去做了一下,贴个地址<br>https://www.cnblogs.com/jsonphp/articles/6517343.html<br>所有代码都是原封不动输进去的。(当然数据库是我自己的)<br> 连接数据库成功,所有代码IDEA提示没有输入错误。<br>启动tomcat服务后出现如下情况![图片说明](https://img-ask.csdn.net/upload/201904/22/1555948137_860888.png) <br>鼠标点上去之后出现这个提示:error during artifact deployment<br>然后我点了一下这个圈圈,![图片说明](https://img-ask.csdn.net/upload/201904/22/1555948216_788182.png) <br>它变成了这个样子![图片说明](https://img-ask.csdn.net/upload/201904/22/1555948291_824212.png)<br>我自己新建了一个新项目什么都没写,tomcat服务可以运行,我把本项目的web.xml文件内所有额外添加的代码全部删除,tomcat服务可以运行,可以显示index.jsp页面,但页面跳转失败,404。我的IDEA是最新版本,你给我的项目作者说了这样一句话: 使用过滤器,要引入jar包:servlet-2_5-api.jar但我引入这个包之后代码反而会报错! ![图片说明](https://img-ask.csdn.net/upload/201904/22/1555948790_167605.png) <br> 请问我哪里操作错了吗,调试一下午了,原封不动的代码都不运行不出来真的很难受。
MySQL数据库连接问题。
[code="java"][/code]我是个Java开发的初学者,最近开始自学Servlet/JSP编程,参考的是孙鑫老师编的《Servlet/Jsp深入详解——基于Tomcat的Web开发》。 在学习“第4章数据库访问”时遇到了问题,我按照书上的代码编写了一个CreateDBServlet.java用于连接数据库,编译是没问题的。进行了部署和配置后,访问时出错了,浏览器显示的错误信息如下: HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) org.sunxin.ch04.servlet.CreateDBServlet.doGet(CreateDBServlet.java:61) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) root cause java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910) com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923) com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273) com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031) com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718) com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298) com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282) java.sql.DriverManager.getConnection(DriverManager.java:525) java.sql.DriverManager.getConnection(DriverManager.java:171) org.sunxin.ch04.servlet.CreateDBServlet.doGet(CreateDBServlet.java:44) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs. -------------------------------------------------------------------------------- Apache Tomcat/6.0.18 CreateDBServlet代码如下: [code="java"]package org.sunxin.ch04.servlet; 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 CreateDBServlet extends HttpServlet { private String userUrl; private String userName; private String password; public void init() throws ServletException { String driverClass=getInitParameter("driverClass"); userUrl=getInitParameter("userUrl"); userName=getInitParameter("userName"); password=getInitParameter("password"); try { Class.forName(driverClass); } catch (ClassNotFoundException ce) { throw new ServletException("加载数据库驱动失败!"); } } public void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException { Connection conn=null; Statement stmt=null; try { conn=DriverManager.getConnection(userUrl,userName,password); stmt=conn.createStatement(); stmt.executeUpdate("create database bookstore"); stmt.executeUpdate("use bookstore"); stmt.executeUpdate("create table bookinfo(id INT not null primary key,title VARCHAR(50) not null,author VARCHAR(50) not null,bookconcern VARCHAR(50) not null,publish_date DATE not null,price FLOAT(4,2) not null,amount SMALLINT,remark VARCHAR(200))ENGINE=InnoDB"); stmt.addBatch("insert into bookinfo values(1,'Java Web 详解','孙鑫','电子工业出版社','2006-4-20',99.00,35,null)"); stmt.addBatch("insert into bookinfo values(2,'Struts 2深入详解','孙鑫','电子工业出版社','2008-6-15',79.00,20,null)"); stmt.addBatch("insert into bookinfo values(3,'Servlet/JSP详解','孙鑫','电子工业出版社','2008-7-1',79.00,10,null)"); stmt.executeBatch(); resp.setContentType("text/html;charset=GBK"); PrintWriter out=resp.getWriter(); out.println("数据库创建成功!"); out.close(); } catch (SQLException se) { throw new ServletException(se); } finally { if(stmt!=null) { try { stmt.close(); } catch (SQLException se) { se.printStackTrace(); } stmt=null; } if(conn!=null) { try { conn.close(); } catch (SQLException se) { se.printStackTrace(); } conn=null; } } } }[/code] web.xml文件如下: [code="java"]<?xml version="1.0" encoding="gb2312"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>createDB</servlet-name> <servlet-class>org.sunxin.ch04.servlet.CreateDBServlet</servlet-class> <init-param> <param-name>driverClass</param-name> <param-value>com.mysql.jdbc.Driver</param-value> </init-param> <init-param> <param-name>userUrl</param-name> <param-value>jdbc:mysql://localhost:3306</param-value> </init-param> <init-param> <param-name>userName</param-name> <param-value>root</param-value> </init-param> <init-param> <param-name>passord</param-name> <param-value>12345678</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>createDB</servlet-name> <url-pattern>/createdb</url-pattern> </servlet-mapping> </web-app> [/code]
我用的是纯驱动连接SQL server数据库,运行的时候显示第128行错误,不知道怎么改。求帮助。
package servlets; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.sql.*; import toolbean.*; public class regservlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response);} /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=gbk"); PrintWriter out = response.getWriter(); ValueBean vb=new ValueBean(); vb.setUsername(MyTools.toChinese(request.getParameter("username"))); vb.setUserpass(request.getParameter("userpass")); vb.setBirthdate(request.getParameter("birthdate")); vb.setGender(MyTools.toChinese(request.getParameter("gender"))); vb.setNativeplace(MyTools.toChinese(request.getParameter("nativeplace"))); vb.settype(MyTools.toChinese(request.getParameter("type"))); String url="jdbc:sqlserver://127.0.0.1:1433;DataBaseName=lkk"; String user="root"; String pwd="123"; String sql=""; Connection conn=null; Statement stmt=null; ResultSet rs=null; try{ sql="select username from user where username='"+vb.getUsername()+"'"; conn=DriverManager.getConnection(url, user, pwd); stmt=conn.createStatement(); rs=stmt.executeQuery(sql); HttpSession session=request.getSession(); if(rs.next()){ PrintWriter pw=response.getWriter(); pw.write("<script language='javascript'>alert('用户名已存在,请重新注册')</script>"); response.sendRedirect("reg.jsp?err=1"); }else{ StringBuffer newsql=new StringBuffer(); newsql.append("insert into user (username,userpass,gender,birthdate,nativeplace,type) values ('"); newsql.append(vb.getUsername()); newsql.append("','"); newsql.append(vb.getUserpass()); newsql.append("','"); newsql.append(vb.getGender()); newsql.append("','"); newsql.append(vb.getBirthdate()); newsql.append("','"); newsql.append(vb.getNativeplace()); newsql.append("','"); newsql.append("会员"); newsql.append("')"); stmt.executeUpdate(newsql.toString()); session.setAttribute("msg_ok","注册成功!"); session.setAttribute("username",vb.getUsername()); response.sendRedirect("regMsg.jsp"); } }catch(Exception e){ out.print(e.toString()); }finally{ try{rs.close();}catch(Exception ee){} try{stmt.close();}catch(Exception ee){} try{conn.close();}catch(Exception ee){} } } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occure */ public void init() throws ServletException { try{ Class.forName("com.microsoft.jdbc.SQLServerDriver"); }catch (Exception e){ throw new ServletException("加载数据库驱动失败!");//这是第128行 } }} 错误描述: javax.servlet.ServletException: 加载数据库驱动失败! servlets.regservlet.init(regservlet.java:128) javax.servlet.GenericServlet.init(GenericServlet.java:212) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) java.lang.Thread.run(Thread.java:619)
连接oracle时候报空指针异常
try { String className = "oracle.jdbc.driver.OracleDriver"; Class.forName(className); System.out.println("加载数据库驱动成功!"); } catch (ClassNotFoundException e) { System.out.println("加载数据库驱动失败!"); e.printStackTrace(); } try { System.out.println("开始连接数据库"); String user = "sys as sysdba"; String password = "123123"; String url = "jdbc:oracle:thin:@焱:1521:XE"; con = DriverManager.getConnection(url, user, password); System.out.print(con); System.out.println("创建数据库连接成功!"); } catch (SQLException e) { System.out.print(con); System.out.println("创建数据库连接失败!"); con = null; e.printStackTrace(); } 如果直接在类里面使用main函数 获取数据库能够连接成功,取出数据,但是在web页面的servlet中使用DBManager dbm = new DBManager(); 就会报空指针异常 java.lang.NullPointerException java.lang.String.<init>(String.java:166) oracle.sql.CharacterSet.AL32UTF8ToString(CharacterSet.java:1516) oracle.jdbc.driver.DBConversion.CharBytesToString(DBConversion.java:588) oracle.jdbc.driver.DBConversion.CharBytesToString(DBConversion.java:541) oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:815) oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:361) oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:413) oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164) oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34) oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752) java.sql.DriverManager.getConnection(DriverManager.java:664) java.sql.DriverManager.getConnection(DriverManager.java:247) util.DBManager.<init>(DBManager.java:33) service.StudentService.stu_Login(StudentService.java:21) MyServlet.LoginPageServlet.doPost(LoginPageServlet.java:35) javax.servlet.http.HttpServlet.service(HttpServlet.java:644) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 最后指向的就是 con = DriverManager.getConnection(url, user, password);这一句连接语句
删除实现不了,数据库已经连上了
at com.wyk.ConnDB.executeUpdata(ConnDB.java:67) at org.apache.jsp.goods_005fdelete_jsp._jspService(goods_005fdelete_jsp.java:81) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) package com.wyk; import java.io.InputStream; import java.sql.*; import java.util.Properties; public class ConnDB { public Connection conn = null; public Statement stmt = null; public ResultSet rs = null; private static Statement st = null; //设置Statement类的对象 private static String propFileName = "/com/connDB.properties"; //指定资源文件保存的位置 private static Properties prop = new Properties(); private static String dbClassName ="com.mysql.jdbc.Driver"; private static String dbUrl = "jdbc:mysql://127.0.0.1:3306/db_wuliu?user=root&password=mysql&useUnicode=true"; public ConnDB(){ try { InputStream in=getClass().getResourceAsStream(propFileName); prop.load(in); //通过输入流对象加载Properties文件 dbClassName = prop.getProperty("DB_CLASS_NAME"); //获取数据库驱动 dbUrl = prop.getProperty("DB_URL", "jdbc:mysql://127.0.0.1:3306/db_wuliu?user=root&password=mysql&useUnicode=true"); } catch (Exception e) { e.printStackTrace(); //输出异常信息 } } public static Connection getConnection() { Connection conn = null; try { Class.forName(dbClassName).newInstance(); conn = DriverManager.getConnection(dbUrl); } catch (Exception ee) { ee.printStackTrace(); } if (conn == null) { System.err.println( "警告: DbConnectionManager.getConnection() 获得数据库链接失败.\r\n\r\n链接类型:" + dbClassName + "\r\n链接位置:" + dbUrl); } return conn; } /* * 功能:执行查询语句 */ public ResultSet executeQuery(String sql) { try { conn = getConnection(); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(sql); } catch (SQLException ex) { System.err.println(ex.getMessage()); } return rs; } /* * 功能:执行更新操作 */ public boolean executeUpdata(String sql) { try { st = conn.createStatement(); //创建声明对象连接 ((ConnDB) st).executeUpdata(sql); //执行添加、修改、删除操作 return true; //如果执行成功则返回true } catch (Exception e) { e.printStackTrace(); return false; //如果执行成功则返回false }} /* * 功能:关闭数据库的连接 */ public void close() { try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(System.err); } } }
java servlet的一个作业题.麻烦各位帮忙解决
** 1.配置本地端口号为99992. 提供留言页面,包括,标题,留言类型,内容提交到serlvet中进行处理、如果必填项为空,跳转重新让用户输入。留言信息完整保存到数据库中,并跳转成功页面,提示用户留言成功。addNote.jsp 增加留言的JSPReceiveNotServlet.java 接收留言信息的servletNote.java 留言实体对象Dbconnection.java 连接数据库并保存留言Success.jsp 成功页面要求不可以使用数据库连接池留言页面需要有JS验证,标题如果为空不允许提交 3.不使用eclipse,手动放置一个应用名称为"manalapp"的应用。该应用为作业2的功能。 并独立运行总共三问.谢谢各位高手帮助. ------------------------------------------------------------------------ **
数据库连接未能成功超过允许的获取尝试的最大数量(30)?
eclipse下创建Java项目测试过,c3p0可以正常获取连接。 创建web项目,访问时报错,同意的c3p0配置文件 <property name="jdbcUrl">jdbc:mysql://localhost:3306/mydb1</property> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="user">root</property> <property name="password">localhost</property> <!-- 池参数配置 --> <property name="acquireIncrement">3</property> <property name="initialPoolSize">10</property> <property name="minPoolSize">2</property> <property name="maxPoolSize">10</property> </default-config> 控制台报错如下; 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@5a71b12e -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@236a9ecb -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:13:33 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [UserServlet] in context with path [/bookstore3] threw exception java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at cn.itcast.servlet.BaseServlet.service(BaseServlet.java:61) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at cn.itcast.servlet.BaseServlet.service(BaseServlet.java:45) ... 17 more Caused by: java.lang.RuntimeException: java.sql.SQLException: Connections could not be acquired from the underlying database! at cn.itcast.bookstore.user.dao.UserDao.findByUsername(UserDao.java:30) at cn.itcast.bookstore.user.service.UserService.regist(UserService.java:21) at cn.itcast.bookstore.user.web.servlet.UserServlet.regist(UserServlet.java:159) ... 22 more Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database! at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:615) at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) at cn.itcast.jdbc.JdbcUtils.getConnection(JdbcUtils.java:43) at cn.itcast.jdbc.TxQueryRunner.query(TxQueryRunner.java:22) at cn.itcast.bookstore.user.dao.UserDao.findByUsername(UserDao.java:28) ... 24 more Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source. at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1406) at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:594) at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:514) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:681) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:608) ... 28 more 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@18d42a08 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@1f57ca86 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@fb4cb7e -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@191942d9 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@4283b70f -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@679614ff -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@2f366294 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:13:33 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:14:03 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@30e8bb73 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620) 十一月 14, 2018 8:14:03 下午 com.mchange.v2.resourcepool.BasicResourcePool forceKillAcquires 警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@7df8f9f6 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests. 十一月 14, 2018 8:14:03 下午 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask run 警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@2707230c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at sun.reflect.GeneratedConstructorAccessor14.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:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) at sun.reflect.GeneratedConstructorAccessor16.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:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:152) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1796) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:620)
Servlet遇到java.lang.NullPointerException问题无法解决,恳求帮助
各位大佬,最近用Jsp+servlet写教务管理系统,其中servlet端有一个问题始终无法解决 ``` 严重: Servlet.service() for servlet [com.jwglxt.data.searchStudent] in context with path [/jwglxt] threw exception java.lang.NullPointerException ``` 目的是根据从前台传来的查询类型和查询关键词在数据库中进行检索,目前前后端数据传递正常,NullPointerException这个问题始终得不到解决,尝试了很多办法都不行,恳请各位大佬施以援手! 代码如下: ```java package com.jwglxt.data; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; //思路:绑定一个弹出框在“搜索”按钮上,弹出框里放置一个datagrid,url为searchStudent @WebServlet("/searchStudent") public class searchStudent extends HttpServlet { @SuppressWarnings({ "null", "null", "null" }) protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //设置编码格式 request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/json; charset=utf-8"); //获取学生信息主码-学号(sno) String name=request.getParameter("name"); System.out.println("搜索类型:"+name); String value=request.getParameter("value"); System.out.println("搜索值:"+value); //姑且赋值 /*String name="sno"; String value="990101";*/ //连接数据库 Connection connection=null; String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL数据库引擎 String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=tjl";//数据源 !!!注意若出现加载或者连接数据库失败一般是这里出现问题 String Name="sa"; String Pwd="19990713"; ResultSet rs=null; String sql="sql"; //定义JSON数组,用于保存从数据库查出来的数据 JSONArray array = new JSONArray(); try { Class.forName(driverName); connection=DriverManager.getConnection(dbURL,Name,Pwd); System.out.println("搜索学生:连接数据库成功"); } catch (ClassNotFoundException e2) { e2.printStackTrace(); }catch (SQLException e) { e.printStackTrace(); } //处理搜索类型 尝试switch语句 /*switch(name) { case "sno":{ try { sql="select * from student where sno=?"; connection.prepareStatement(sql); pstmt.setString(1,value); //rs=pstmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); };break; }//case }//switch */ //处理搜索类型 尝试If语句 if(name!=null) { if("sno".equals(name)){ try { //仅构造SQL语句,暂不运行 sql="select * from student where sno=?"; PreparedStatement pstmt=connection.prepareStatement(sql); pstmt.setString(1,value); rs = pstmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } } else if("sname".equals(name)){ try { //仅构造SQL语句,暂不运行 sql="select * from student where sname=?"; PreparedStatement pstmt=connection.prepareStatement(sql); pstmt.setString(1,value); rs = pstmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } } else if("sex".equals(name)){ try { //仅构造SQL语句,暂不运行 sql="select * from student where sex=?"; PreparedStatement pstmt=connection.prepareStatement(sql); pstmt.setString(1,value); rs = pstmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } } else if("dno".equals(name)){ try { //仅构造SQL语句,暂不运行 sql="select * from student where dno=?"; PreparedStatement pstmt=connection.prepareStatement(sql); pstmt.setString(1,value); rs = pstmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } } else { try { //仅构造SQL语句,暂不运行 sql="select * from student where dormno=?"; PreparedStatement pstmt=connection.prepareStatement(sql); pstmt.setString(1,value); rs = pstmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } } System.out.println(sql); } try { // 获取列数 ResultSetMetaData metaData = rs.getMetaData(); int columnCount = metaData.getColumnCount(); while (rs.next()) { JSONObject jsonObj = new JSONObject(); // 遍历每一列 for (int i = 1; i <= columnCount; i++) { String columnName =metaData.getColumnLabel(i); String value2 = rs.getString(columnName); try { jsonObj.put(columnName, value2); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } array.put(jsonObj); } } catch (SQLException e1) { e1.printStackTrace(); } //关闭 try { if(rs!=null) rs.close(); //pstmt.close(); connection.close(); } catch (SQLException e) { e.printStackTrace(); } //PrintWriter out = response.getWriter(); System.out.println(array); }//总类 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } public static void main(String args[]) { searchStudent ss=new searchStudent(); try { ss.doGet(null, null); } catch (ServletException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } ```
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
【JSON解析】浅谈JSONObject的使用
简介 在程序开发过程中,在参数传递,函数返回值等方面,越来越多的使用JSON。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,同时也易于机器解析和生成、易于理解、阅读和撰写,而且Json采用完全独立于语言的文本格式,这使得Json成为理想的数据交换语言。 JSON建构于两种结构: “名称/值”对的集合(A Collection of name/va...
程序员请照顾好自己,周末病魔差点一套带走我。
程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
只因接了一个电话,程序员被骗 30 万!
今天想给大家说一个刚刚发生在我身边的一起真实的诈骗经历,我的朋友因此被骗走30万。注:为了保护当事人隐私,部分情节进行了修改。1平安夜突来的电话开始以为就像普通的诈骗一样,想办法让你把钱...
我一个37岁的程序员朋友
周末了,人一旦没有点事情干,心里就瞎想,而且跟几个老男人坐在一起,更容易瞎想,我自己现在也是 30 岁了,也是无时无刻在担心自己的职业生涯,担心丢掉工作没有收入,担心身体机能下降,担心突...
python自动下载图片
近日闲来无事,总有一种无形的力量萦绕在朕身边,让朕精神涣散,昏昏欲睡。 可是,像朕这么有职业操守的社畜怎么能在上班期间睡瞌睡呢,我不禁陷入了沉思。。。。 突然旁边的IOS同事问:‘嘿,兄弟,我发现一个网站的图片很有意思啊,能不能帮我保存下来提升我的开发灵感?’ 作为一个坚强的社畜怎么能说自己不行呢,当时朕就不假思索的答应:‘oh, It’s simple. Wait for me for a ...
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
Java 14 都快来了,为什么还有这么多人固守Java 8?
从Java 9开始,Java版本的发布就让人眼花缭乱了。每隔6个月,都会冒出一个新版本出来,Java 10 , Java 11, Java 12, Java 13, 到2020年3月份,...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
讲真,这两个IDE插件,可以让你写出质量杠杠的代码
周末躺在床上看《拯救大兵瑞恩》 周末在闲逛的时候,发现了两个优秀的 IDE 插件,据说可以提高代码的质量,我就安装了一下,试了试以后发现,确实很不错,就推荐给大家。 01、Alibaba Java 代码规范插件 《阿里巴巴 Java 开发手册》,相信大家都不会感到陌生,其 IDEA 插件的下载次数据说达到了 80 万次,我今天又贡献了一次。嘿嘿。 该项目的插件地址: https://github....
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
python爬取百部电影数据,我分析出了一个残酷的真相
2019年就这么匆匆过去了,就在前几天国家电影局发布了2019年中国电影市场数据,数据显示去年总票房为642.66亿元,同比增长5.4%;国产电影总票房411.75亿元,同比增长8.65%,市场占比 64.07%;城市院线观影人次17.27亿,同比增长0.64%。 看上去似乎是一片大好对不对?不过作为一名严谨求实的数据分析师,我从官方数据中看出了一点端倪:国产票房增幅都已经高达8.65%了,为什...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
【程序人生】程序员接私活常用平台汇总
00. 目录 文章目录00. 目录01. 前言02. 程序员客栈03. 码市04. 猪八戒网05. 开源众包06. 智城外包网07. 实现网08. 猿急送09. 人人开发10. 开发邦11. 电鸭社区12. 快码13. 英选14. Upwork15. Freelancer16. Dribbble17. Remoteok18. Toptal19. AngelList20. Topcoder21. ...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
立即提问