| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1138 人关注过本帖
标题:急!JSP操作SqlServer2000数据库问题
只看楼主 加入收藏
swehenry
Rank: 2
等 级:论坛游民
帖 子:45
专家分:14
注 册:2007-11-11
收藏
 问题点数:0 回复次数:5 
急!JSP操作SqlServer2000数据库问题


这个是操作数据库的代码

程序代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DB {
    private final String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Blog";
    private final String userName = "sa";
    private final String password = "sa";
    private Connection con = null;
    private Statement stm=null;
    
    /* 通过构造方法加载数据库驱动 */
    public DB(){
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("加载数据库驱动失败!");
        }        
    }
    /* 创建数据库连接 */
    public void createCon() {
        try {
             con = DriverManager.getConnection(url, userName, password);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("获取数据库连接失败!");
        }
    }
    /* 获取Statement对象 */
    public void getStm(){
           createCon();
        try {
            stm=con.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("创建Statement对象失败!");
        }
    }
    /** 
     * @功能 对数据库的增加、修改和删除的操作
     * @参数 sql为要执行的SQL语句
     * @返回值 boolean型值 
     */
    public boolean executeUpdate(String sql) {
        System.out.println(sql);
        boolean mark=false;
        try {
            getStm();
            int iCount = stm.executeUpdate(sql);
            if(iCount>0)                
                mark=true;            
            else
                mark=false;
        } catch (Exception e) {
            e.printStackTrace();
            mark=false;
        }
        return mark;
    }
    /* 查询数据库 */
    public ResultSet executeQuery(String sql) {
        ResultSet rs=null;
        try {
            getStm();
            try {
                rs = stm.executeQuery(sql);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("查询数据库失败!");
            }
        } catch (Exception e) {
            e.printStackTrace();          
        }
        return rs;
    }
    /* 关闭数据库的操作 */
    public void closed() {
        if(stm!=null)
            try {
                stm.close();
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("关闭stm对象失败!");
            }
        if(con!=null)
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("关闭con对象失败!");
            }
    }
}


这个是控制台信息

程序代码:
2009-12-23 23:34:08 org.apache.catalina.core.AprLifecycleListener init
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Program Files\Genuitec\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;d:\Program Files\Genuitec\Common\plugins\com.genuitec.eclipse.easie.tomcat.myeclipse_7.5.0.zmyeclipse75020090612\tomcat\bin
2009-12-23 23:34:09 org.apache.coyote.http11.Http11Protocol init
严重: Error initializing endpoint
 Address already in use: JVM_Bind:8080
    at org.apache.tomcat.(JIoEndpoint.java:501)
    at org.apache.coyote.http11.Http11Protocol.init(Http11Protocol.java:177)
    at org.apache.catalina.connector.Connector.initialize(Connector.java:1059)
    at org.apache.catalina.core.StandardService.initialize(StandardService.java:677)
    at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:792)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:518)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
2009-12-23 23:34:09 org.apache.catalina.startup.Catalina load
严重: Catalina.start
LifecycleException:  Protocol handler initialization failed:  Address already in use: JVM_Bind:8080
    at org.apache.catalina.connector.Connector.initialize(Connector.java:1061)
    at org.apache.catalina.core.StandardService.initialize(StandardService.java:677)
    at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:792)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:518)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:412)
2009-12-23 23:34:09 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1180 ms
2009-12-23 23:34:09 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2009-12-23 23:34:09 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.13
2009-12-23 23:34:11 org.apache.coyote.http11.Http11Protocol start
严重: Error starting endpoint
 Address already in use: JVM_Bind:8080
    at org.apache.tomcat.(JIoEndpoint.java:501)
    at org.apache.tomcat.(JIoEndpoint.java:515)
    at org.apache.coyote.http11.Http11Protocol.start(Http11Protocol.java:204)
    at org.apache.catalina.connector.Connector.start(Connector.java:1132)
    at org.apache.catalina.core.StandardService.start(StandardService.java:531)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2009-12-23 23:34:11 org.apache.catalina.startup.Catalina start
严重: Catalina.start: 
LifecycleException:  service.getName(): "Catalina";  Protocol handler start failed:  Address already in use: JVM_Bind:8080
    at org.apache.catalina.connector.Connector.start(Connector.java:1139)
    at org.apache.catalina.core.StandardService.start(StandardService.java:531)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2009-12-23 23:34:11 org.apache.catalina.startup.Catalina start
信息: Server startup in 1973 ms
2009-12-23 23:34:11 org.apache.catalina.core.StandardServer await
严重: StandardServer.await: create[8005]: 
 Address already in use: JVM_Bind
    at (Native Method)
    at (PlainSocketImpl.java:359)
    at (ServerSocket.java:319)
    at (ServerSocket.java:185)
    at org.apache.catalina.core.StandardServer.await(StandardServer.java:373)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:630)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:590)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
    at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at com.yxq.toolsbean.DB.createCon(DB.java:28)
    at com.yxq.toolsbean.DB.getStm(DB.java:36)
    at com.yxq.toolsbean.DB.executeQuery(DB.java:69)
    at com.yxq.dao.LogonDao.getMaster(LogonDao.java:20)
    at com.yxq.servlet.IndexServlet.<clinit>(IndexServlet.java:68)
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
    at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122)
    at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918)
    at java.lang.reflect.Field.getFieldAccessor(Field.java:899)
    at java.lang.reflect.Field.set(Field.java:657)
    at org.apache.catalina.loader.WebappClassLoader.clearReferences(WebappClassLoader.java:1615)
    at org.apache.catalina.loader.WebappClassLoader.stop(WebappClassLoader.java:1495)
    at org.apache.catalina.loader.WebappLoader.stop(WebappLoader.java:707)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4534)
    at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
    at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1180)
    at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1151)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:313)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
    at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
    at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:448)
    at org.apache.catalina.core.StandardService.stop(StandardService.java:584)
    at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
    at org.apache.catalina.startup.Catalina.stop(Catalina.java:616)
    at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:659)
获取数据库连接失败!
java.lang.NullPointerException
    at com.yxq.toolsbean.DB.getStm(DB.java:38)
    at com.yxq.toolsbean.DB.executeQuery(DB.java:69)
    at com.yxq.dao.LogonDao.getMaster(LogonDao.java:20)
    at com.yxq.servlet.IndexServlet.<clinit>(IndexServlet.java:68)
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
    at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122)
    at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918)
    at java.lang.reflect.Field.getFieldAccessor(Field.java:899)
    at java.lang.reflect.Field.set(Field.java:657)
    at org.apache.catalina.loader.WebappClassLoader.clearReferences(WebappClassLoader.java:1615)
    at org.apache.catalina.loader.WebappClassLoader.stop(WebappClassLoader.java:1495)
    at org.apache.catalina.loader.WebappLoader.stop(WebappLoader.java:707)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4534)
    at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
    at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1180)
    at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1151)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:313)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
    at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
    at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:448)
    at org.apache.catalina.core.StandardService.stop(StandardService.java:584)
    at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
    at org.apache.catalina.startup.Catalina.stop(Catalina.java:616)
    at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:659)



这个是页面中显示的内容

程序代码:
HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

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

exception 

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

java.lang.NullPointerException
    com.yxq.dao.FriendDao.queryFriend(FriendDao.java:47)
    com.yxq.servlet.IndexServlet.doPost(IndexServlet.java:52)
    com.yxq.servlet.IndexServlet.doGet(IndexServlet.java:25)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
    org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:56)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


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


--------------------------------------------------------------------------------

Apache Tomcat/6.0.13




本人新手,错误一直调试不好,麻烦各位大大帮忙看看。急死人了~







[ 本帖最后由 swehenry 于 2009-12-23 23:56 编辑 ]
搜索更多相关主题的帖子: 数据库 JSP 
2009-12-23 23:54
swehenry
Rank: 2
等 级:论坛游民
帖 子:45
专家分:14
注 册:2007-11-11
收藏
得分:0 
恳求各位大大帮忙找找错误,整了一天了
2009-12-23 23:56
swehenry
Rank: 2
等 级:论坛游民
帖 子:45
专家分:14
注 册:2007-11-11
收藏
得分:0 
在线等~
2009-12-24 12:18
柠檬可乐
Rank: 4
等 级:业余侠客
威 望:6
帖 子:66
专家分:205
注 册:2009-6-16
收藏
得分:0 
private final String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Blog";
private final String userName = "sa";
private final String password = "sa";
private Connection con = null;
private Statement stm=null;

试一下把这些定义成public类型
2009-12-24 16:40
swehenry
Rank: 2
等 级:论坛游民
帖 子:45
专家分:14
注 册:2007-11-11
收藏
得分:0 
修改了下,错误还是存在
2009-12-25 10:29
lampeter123
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:54
帖 子:2508
专家分:6424
注 册:2009-1-30
收藏
得分:0 
根据错误提示,你的8080端口被其他程序占用了,Tomcat服务器启动不了

[ 本帖最后由 lampeter123 于 2009-12-25 14:56 编辑 ]

你的优秀和我的人生无关!!!!
    
    我要过的,是属于我自己的生活~~~
2009-12-25 14:55
快速回复:急!JSP操作SqlServer2000数据库问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028047 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved