首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

数据库有关问题java.sql.SQLException: Column not found,

2012-01-09 
数据库问题java.sql.SQLException: Column not found,急!!!!救命啊我读不了数据库啊各位大侠教教我~~我的

数据库问题java.sql.SQLException: Column not found,急!!!!
救命啊
我读不了数据库啊
各位大侠教教我~~

我的代码:
/*
  *   Main.java
  *
  *   Created   on   2007年3月20日,   上午12:33
  *
  *   To   change   this   template,   choose   Tools   |   Template   Manager
  *   and   open   the   template   in   the   editor.
  */

package   managersystem;
import   java.sql.*;

/**
  *
  *   @author   Administrator
  */
public   class   Main   {


       
        /**   Creates   a   new   instance   of   Main   */
        public   Main()   {
        }
       
        /**
          *   @param   args   the   command   line   arguments
          */
        public   static   void   main(String   argv[])   {
                //   TODO   code   application   logic   here
          try{
                          Connection   con=null;
                          Statement   stmt=null;
                          ResultSet   rs=null;
                         
                          Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
           
                          String   url   =   "jdbc:odbc:students ";
                         
                          con   =   DriverManager.getConnection(url);
                         
                          stmt   =   con.createStatement();
                         
                          String   sqlstmt= "select   sno,   name,   birthday,   department "+ "   from   students   where   sex= '男 ' ";
                         
                          rs   =   stmt.executeQuery   (sqlstmt);
                         
                          System.out.println( "-----------查询结果----------- ");
                          System.out.println();


                          System.out.println( "学号--姓名--出生日期----院系名称-- ");
                          while   (rs.next()){
                                  String   sno=rs.getString( "sno ");
                                  String   name=   rs.getString( "name ");
                                  Date   birthday=   rs.getDate( "birthday ");
                                  String   department=   rs.getString( "departement ");
                                 
                                  System.out.print(sno+ "   "+name+ "   ");
                                  System.out.println(birthday+ "   "+department);
                    }
          }       catch   (Exception   e)   {
                  System.out.println(e);    
              }
        }
       
}


提示出错:
init:
deps-jar:
compile:
-----------查询结果-----------

学号--姓名--出生日期----院系名称--
java.sql.SQLException:   Column   not   found
ERROR:   JDWP   Unable   to   get   JNI   1.2   environment,   jvm-> GetEnv()   return   code   =   -2
JDWP   exit   error   AGENT_ERROR_NO_JNI_ENV(183):     [../../../src/share/back/util.c:820]
debug:


到底是什么问题!?
急啊~~


[解决办法]
Column not found
它不是告诉你了吗?
[解决办法]
String sno=rs.getString( "sno "); 
String name= rs.getString( "name "); 
 Date birthday= rs.getDate( "birthday "); 
 String department= rs.getString( "departement "); 

这几个getString中的String参数在数据库表students中中没有对应的列,可能是你拼写错误。但从单词的字面上看,你的好像都是对的,就是不知道你的"name "中是不是有一个空格啊?要是有的话,去掉得了。要么就用trim()试一试。

热点排行