在连接数据库的时候报出这样的错误,实在不知道是什么地方有错求解源码连接是这样的request.setCharacterEncoding("utf-8");Stringname=request.getParameter("name");Stringtitle=re...
在连接数据库的时候报出这样的错误,实在不知道是什么地方有错求解
源码连接是这样的
request.setCharacterEncoding("utf-8");
String name=request.getParameter("name");
String title=request.getParameter("title");
String message=request.getParameter("message");
DataSource ds=null;
try {
Context context=new InitialContext();
ds=(DataSource)context.lookup("java:/comp/enw/jdbc/mysqlds");
} catch (Exception e) {
System.out.println("获取的数据出错");
}
try {
Connection conn=ds.getConnection();
String sql="insert into weblog (name,title,message,created_time)values(?,?,?,now())";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, title);
pstmt.setString(3, message);
int result=pstmt.executeUpdate();
System.out.println(result);
报错结果:
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.conntest.Connservlet.doPost(Connservlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
展开