请问我的CONNECTION为什么不能creatstatement?

ortenga 2004-09-27 10:48:34
只要一执行Statement stmt = con.createStatement() ;这句就会报错,如果不要这部分,就可以运行过去,是不是SQL SERVER中什么没设置对?之前在JDBC.java中的连接都没有问题的。
...全文
72 点赞 收藏 10
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
禽兽v5 2004-09-28
java.lang.NullPointerException
org.apache.jsp.liuyanben.ly_jsp._jspService(ly_jsp.java:75

查看
%CATALINA_HOME%\work\Catalina\localhost\ROOT\org\apache\jsp\liuyanben\ly_jsp.java
第75行
回复
ortenga 2004-09-28
现在又变成了这个错误了,估计是数据库连接有问题。。。。。?
javax.servlet.ServletException: [Microsoft][ODBC ???????] ???????????????????
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.liuyanben.ly_jsp._jspService(ly_jsp.java:240)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


root cause

java.sql.SQLException: [Microsoft][ODBC ???????] ???????????????????
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
wu.jdbc.executeQuery(jdbc.java:28)
org.apache.jsp.liuyanben.ly_jsp._jspService(ly_jsp.java:75)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

回复
禽兽v5 2004-09-28
java.sql.SQLException: [Microsoft][ODBC ???????] ???????????????????

后来这个确实是连接错误。另外它是Microsoft Odbc连接驱动.(嗯?不是jdbc也可以?)
回复
yeshucheng 2004-09-28
我大致写了个,你看看是否意思到位了(已经测试通过):
public class TestBean{
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");//这里用到的是什么数据库的driver就写相应的就可以
String url = "jdbc:oracle:thin:@localhost:1521:数据库名称";
String user = "...";
String password = "....";
Connection conn = DriverManager.getConnection(url, user, password);
conn conn=new conn();
Connection con=conn.getConn();
Statement stmt = con.createStatement();
String sql = "select..... ";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println("first:"+rs.getString(1));
System.out.println("second:"+rs.getString(2));
}
rs.close();
stmt.close();
con.close();
}
catch (Exception e) {
e.printStackTrace();
System.out.println("连接失败!");
}

}
}
回复
JOBLin 2004-09-28
应该不是连接字符串的问题,因为报的是Statement stmt = con.createStatement()错误,应该是数据源有问题,
回复
禽兽v5 2004-09-28
是数据库联接错误,重点检查连接字符串。
回复
xiangbo520 2004-09-28
空指针错误,可能是由于你的con没有初始化所引起的。
回复
禽兽v5 2004-09-27
睡前up.
回复
ortenga 2004-09-27
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:346)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


root cause

java.lang.NullPointerException
org.apache.jsp.liuyanben.ly_jsp._jspService(ly_jsp.java:75)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.25 logs.

回复
haroyy 2004-09-27
报什么错??关键
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告