是不是你sql语句里地表名写错了呀

解决方案 »

  1.   

    这是怎么回事?selserver的sp3我也打了。还有更奇怪的是,以上是我连接本地的数据库,连接远程数据库就没有问题
    ----------------------------------------------------
                   你是连接内容一样的数据库吗?你看看你的服务器地址有无打错,很可能是地址错了,要不然就是上面的说法了,最好你把代码贴出来看看。
      

  2.   

    user_info可能为你的库中的一个表,你可能写错名称了。
      

  3.   

    谢谢各位,这两天网络有问题,没能及时上来,数据库名、表名我都检查了,我确认没有错误,远程服务器的表名我也检查了,和本地的是一样的包括字段名。郁闷,谢谢大家!以下是我的链接数据库的代码public class DBConn
    {
     public String sql_driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
     public String sql_url = "jdbc:microsoft:sqlserver://localhost:1433;";
     public String sql_DBName = "DatebaseName=shopping;";
     public String user = "user=sa;";
     public String pwd = "password=sa"; Connection conn = null;
     Statement stmt = null;
     ResultSet rs = null; public boolean setDriver(String drv)
     {
      this.sql_driver = drv;
      return true;
     } public String getDriver()
     {
      return this.sql_driver;
     } public boolean setUrl(String url)
     {
      this.sql_url = url;
      return true;
     } public boolean setDBName(String dbname)
     {
      this.sql_DBName = dbname;
      return true;
     } public String getDBName()
     {
      return this.sql_DBName;
     } public boolean setUser(String user)
     {
      this.user = user;
      return true;
     } public String getUser()
     {
      return this.user;
     } public boolean setPwd(String pwd)
     {
      this.pwd = pwd;
      return true;
     } public String getPwd()
     {
      return this.pwd;
     } public DBConn()
     {
      try{
       Class.forName(sql_driver);//
       this.conn = DriverManager.getConnection(sql_url+sql_DBName+user+pwd);
       this.stmt = this.conn.createStatement();
      }catch(Exception e){
       System.out.println(e.toString());
      }
     }                //
     public ResultSet executeQuery(String strSql)
     {
      try{
       this.rs = stmt.executeQuery(strSql);
       return this.rs;
      }catch(SQLException e){
       System.out.println(e.toString());
       return null;
      }catch(NullPointerException e){
       System.out.println(e.toString());
       return null;
      }
     }                //
     public boolean execute(String strSql)
     {
      try{
       if(this.stmt.executeUpdate(strSql) == 0)
        return false;
       else
        return true;
      }catch(SQLException e){
       System.out.println(e.toString());
       return false;
      }catch(NullPointerException e){
       System.out.println(e.toString());
       return false;
      }
     }                //
     public boolean rs_absolute(int row)
     {
      try{
       this.rs.absolute(row);
       return true;
      }catch(SQLException e){
       System.out.println(e.toString());
       return false;
      }
     } public void rs_afterLast()
     {
      try{
       this.rs.afterLast();
      }catch(SQLException e){
       System.out.println(e.toString());
      }
     } public void rs_beforeFirst()
     {
      try{
       this.rs.beforeFirst();
      }catch(SQLException e){
       System.out.print(e.toString());
      }
     } public void rs_close()
     {
      try{
       this.rs.close();
      }catch(SQLException e){
       System.out.print(e.toString());
      }
     } public void rs_deleteRow()
     {
      try{
       this.rs.deleteRow();
      }catch(SQLException e){
       System.out.print(e.toString());
      }
     } public boolean rs_first()
     {
      try{
       this.rs.first();
       return true;
      }catch(SQLException e){
       System.out.print(e.toString());
       return false;
      }
     } public String rs_getString(String column)
     {
      try{
       return this.rs.getString(column);
      }catch(SQLException e){
       System.out.println(e.toString());
       return null;
      }
     }                //
                    //
                    //
     public String rs_getHtmlString(String column)
     {
      try{
       String str1 = this.rs.getString(column);
       String str2 = "\r\n";
       String str3 = "<br>";
       return this.replaceAll(str1,str2,str3);
      }catch(SQLException e){
       System.out.println(e.toString());
       return null;
      }
     }
     
                    //
     private static String replaceAll(String str1,String str2,String str3)
     {
      StringBuffer strBuf = new StringBuffer(str1);
         int index=0;
      while(str1.indexOf(str2,index)!=-1)
      {
       index=str1.indexOf(str2,index);
       strBuf.replace(str1.indexOf(str2,index),str1.indexOf(str2,index)+str2.length(),str3);
       index=index+str3.length();    str1=strBuf.toString();
      }
      return strBuf.toString();
     }  public int rs_getInt(String column)
     {
      try{
       return this.rs.getInt(column);
      }catch(SQLException e){
       System.out.println(e.toString());
       return -1;
      }
     } public int rs_getInt(int column)
     {
      try{
       return this.rs.getInt(column);
      }catch(SQLException e){
       System.out.println(e.toString());
       return -1;
      }
     } public boolean rs_next()
     {
      try{
       return this.rs.next();
      }catch(SQLException e){
       System.out.println(e.toString());
       return false;
      }
     }                //
     public boolean hasData()
     {
      try{
       boolean has_Data = this.rs.first();   
       this.rs.beforeFirst();
       return has_Data;
      }catch(SQLException e){
       System.out.println(e.toString());
       return false;
      }
     } public boolean rs_last()
     {
      try{
       return this.rs.last();
      }catch(SQLException e){
       System.out.println(e.toString());
       return false;
      }
     } public boolean rs_previous()
     {
      try{
       return this.rs.previous();
      }catch(Exception e){
       System.out.println(e.toString());
       return false;
      }
     }
     public static void main(String args[])
     {
      try{
       DBConn myconn = new DBConn();
       ResultSet rs = myconn.executeQuery("select * from user_info");
       while (myconn.rs.next())  
       {
        int id = myconn.rs_getInt("id") + 1;
        System.out.print(id);
        System.out.println(myconn.rs_getInt("id") + myconn.rs_getString("name"));
        
        //System.out.println('\n' + myconn.rs_getHtmlString("name"));
        //System.out.println(myconn.rs.getString("name") + myconn.rs_getInt(1));
       }
      }catch(Exception e){
       System.err.println(e.toString());
      }
     } 
    }
      

  4.   

    jdbc-odbc连接的吧..
    取字段的顺序要和表字段顺序保持一致的 ..........
      

  5.   

    哦,是一样的呀,我刚又检查了。好郁闷,是不是win2003的问题呀!!!
      

  6.   

    sql_url = "jdbc:microsoft:sqlserver://localhost:1433/dbname";
      

  7.   

    还是不行呀,以为是系统的问题,我刚在2000下也试了,还是不行呀,晕了,到底是那出错了那?这是一个用来测试的例子:import java.sql.*;
    public class testsqlserver{
    public static void main(String[] args){
    try{
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
        String url="jdbc:microsoft:sqlserver://xn-yang:1433;DatebaseName=test";
    String user="sa";
    String pass="sa";
    Connection conn=DriverManager.getConnection(url,user,pass);
    Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stmt.executeQuery("select * from tbluser where name='xn'");
    System.out.println("Connection");
    }catch(Exception e){
    System.out.println(e.toString());
    }
    }
    }还是报错,同样的问题!
      

  8.   

    把这段语句
    Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);里面的参数去掉.
      

  9.   

    远程的数据库能连接,说明远程的JSP服务器已经配置好了JDBC的.JAR文件
    你在本地用BEAN能连接数据库,说明你的JDBC下的三个.JAR文件已经加入CLASSPATH
    而中JSP中的连接数据库不能使用,说明你的JDBC三个.JAR文件没有配置到WEB-INF\LIB下
      

  10.   

    哦,谢谢,可能我没说清楚,还没倒jsp那一步,我先测试bean是否正确,就出现了以上这些毛病!想把问题弄清楚,GhostFire再教教我!