HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException com.dao.impl.AdminInfoImpl.login(AdminInfoImpl.java:24) com.servlet.LoginServlet.doPost(LoginServlet.java:26) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 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.20 logs. --------------------------------------------------------------------------------Apache Tomcat/6.0.20 f运行时的错误
import java.sql.DriverManager;
import java.sql.Statement;
public class JdbcDemo {
public static void main(String[] args) {
try {
//数据库连接MySQL
Connection conn=null;
Statement stmt=null;
//MySQL驱动名
String className="com.mysql.jdbc.Driver";
//要连接的URL,localhost是连接本地,如果连接其他机器改为IP地址3306是Mysql默认端口,test是你要操作的数据库的名称,数据库要有才行
String url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8";
//mySql的用户名密码要改为你自己的mysql数据库的用户名、密码
String user="root";
String password="1314520";
//下面三行是固定写法
Class.forName(className);
conn=DriverManager.getConnection(url, user, password);
stmt=conn.createStatement();
//开始插入操作,ut_test是test数据库中的一张表,有name,age,email三个字段,插入的值是'刘尹',22,'[email protected]'。
String sql="insert into ut_test(name,age,email) values ('刘尹',22,'[email protected]') ";
//执行操作
stmt.execute(sql);
System.out.println("插入成功!");
} catch(Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
别忘了导驱动包
com.dao.impl.AdminInfoImpl.login(AdminInfoImpl.java:24)
com.servlet.LoginServlet.doPost(LoginServlet.java:26)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
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.20 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.20
f运行时的错误
E:\Java\lib\ext\文件夹中,我的Java安装在E:\Java\中