Topic: 数据库好像连不上

  Print this page

1.数据库好像连不上 Copy to clipboard
Posted by: JAVA生
Posted on: 2006-03-13 11:25

我的系统是XP-Professional我安装的是SQLServer2000我用的是TOMCAT
我的代码在别人的机器上能运行,但在自己的就不行!请指导指导!!谢谢。
DbBean码
package txl;
import java.util.Date;
import java.sql.*;
import java.util.*;
public class DbBean
{
   String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=swxx";
public Connection sqlCon=null;
public Statement sqlStmt=null;
TxlInfo txlinfo;
public DbBean()throws Exception
{
  
try
{
   Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
   sqlCon=DriverManager.getConnection(url,"sa","sa");
sqlStmt=sqlCon.createStatement();
   sqlCon.setAutoCommit(true);
  //Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
     //sqlCon=DriverManager.getConnection(url,"sa","sa");
      //sqlStmt=sqlCon.createStatement();
  }
catch(Exception e)
   {
System.out.println("数据库错误2");//TOMCAT内显示这个错误!
  
}
  }

   public ResultSet ShowInfo(String sql)
   {
     ResultSet rs=null;
     try
     {
   rs=sqlStmt.executeQuery(sql);
   }
   catch(Exception e)
   {
     e.printStackTrace();
   }
     return rs ;
     }  
   public void SetTxlInfo(TxlInfo txlinfo)
  
   {
   this.txlinfo=txlinfo;  
     }
   public void addnew()throws Exception
   {
   try
   {
   String addsql="insert into txl_tab(name,dz,dh,yb,oicq,lrsj)values(?,?,?,?,?,?)"  ;
   PreparedStatement pstm=sqlCon.prepareStatement(addsql);
   pstm.setString(1,new String(txlinfo.getName().trim().getBytes("ISO8859_1"),"gb2312"));
   pstm.setString(2,new String(txlinfo.getDz().trim().getBytes("ISO8859_1"),"gb2312"));
   pstm.setString(3,txlinfo.getDh());  
   pstm.setInt(4,txlinfo.getYb());  
   pstm.setString(5,txlinfo.getOicq());  
   pstm.setDate(6,new java.sql.Date(new java.util.Date().getTime()));  
   pstm.executeUpdate();
  
   }
   catch(Exception e)
   {
   e.printStackTrace();
   throw e;  
     }
     
        
     }
     
  
}
错误信息
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:358)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

java.lang.NullPointerException
  txl.DbBean.addnew(DbBean.java:54)
  org.apache.jsp.txladdnew_jsp._jspService(txladdnew_jsp.java:79)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

}

2.Re:数据库好像连不上 [Re: JAVA生] Copy to clipboard
Posted by: forsoft
Posted on: 2006-03-13 21:52

java.lang.NullPointerException
txl.DbBean.addnew(DbBean.java:54)
org.apache.jsp.txladdnew_jsp._jspService(txladdnew_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

3.Re:数据库好像连不上 [Re: JAVA生] Copy to clipboard
Posted by: JAVA生
Posted on: 2006-03-15 23:50

终于好了。 果然是SQLServer的问题!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923