解决方案 »
- 学习servlet中过滤器的使用问题
- jsp传参给JavaScript参数验证问题
- JSP中,如何将查询到的多条信息放到一个文本框里
- 怎样去掉js弹出框的标题,改成自己的提示
- jbuilder 与vss 更改工程名······
- 一个关于javascript取值的问题
- 求大侠解决一个jsp + javabean的问题
- 大家帮帮我!!!
- 请教ie处理来自response的多个文件的数据流以及解析和显示的问题
- 用SmartUpload类上传文件有大小限制吗??或者ENCTYPE='multipart/form-data'的form对于上传文件大小有限制??为什么大于1M的文件一上传就显示找不到页面啊!!
- 简单的Java web应用开发
- 怎么选中从数据库查询到的复选框?
String username = "root";
String password = "1234";
String url = "jdbc:mysql://localhost:3306/test";
conn = DriverManager.getConnection(url, username, password);
Conn为null,没有实例化。才会java.lang.NullPointerException
而你实例化conn方法又是public void Conn()方法,你根本就没有调用这个方法。
Connection connection = DriverManager.getConnection
(“jdbc:mysql://localhost:3306/test“, "scott", "tiger");
For Oracle:
Connection connection = DriverManager.getConnection
("jdbc:oracle:thin:@liang.armstrong.edu:1521:orcl", "scott", "tiger");
拿去试试
对的,
mysql数据库默认端口是3306,可一不写的
at com.javaBean.Conn.executeQuery(Conn.java:42)
空指针嘛,conn没有初始化就在调用方法来,
改成
static{
try {
Class.forName(strDBDriver);
conn=DriverManager.getConnection(strConnectionString); //获得数据库连接
stmt=conn.createStatement();
} catch(ClassNotFoundException e) {
System.out.println("数据库连接失败!");
}catch(SQLException e){System.out.println("数据库连接失败!");}}
Conn为null.你都木有实例化啊。 然后你的方法也不是静态的。
Conn为空 , 你应该先判断一下 Conn != null
try {
Class.forName(strDBDriver);
conn=DriverManager.getConnection(strConnectionString); //获得数据库连接
stmt=conn.createStatement();
} catch(ClassNotFoundException e) {
System.out.println("数据库连接失败!");
}catch(SQLException e){System.out.println("数据库连接失败!");}
}
static {
try {
Class.forName(strDBDriver);
conn=DriverManager.getConnection(strConnectionString); //获得数据库连接
stmt=conn.createStatement();
} catch(ClassNotFoundException e) {
System.out.println("数据库连接失败!");
}catch(SQLException e){System.out.println("数据库连接失败!");}}