import java.io.*;
import java.util.*;
import java.sql.*;
public class bean
{
Connection Con=null;
public bean(){BuildConnection();}
public void BuildConnection(){
try     {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Con = DriverManager.getConnection("jdbc:odbc:xxy","sa","");

}catch (Exception e)    {
System.out.println(e.getMessage());}
              }public Connection getConnection()
{
if(Con==null)
BuildConnection();
return this.Con;
}
public void close()
{try{
Con.close();
Con=null;
    }
catch(SQLException e){
System.out.println(e.getMessage());
                   }
}
try{  
String pass;Statement stm=Con.createStatement();
     public String checkd(String username,String password)
    { 
   
     String sql="select password from dl where name='"+ username + "'";
        ResultSet rs=stm.executeQuery(sql);
        if(rs==null)
        return("请输入用户名!");
        while(rs.next()){
         pass = rs.getString(2);
            
                         }
      if(pass.equals(password))
            return("登录成功!");
        else
            return("密码错误!");                        
                                   
                            }
}
catch(SQLException e){
System.out.println(e.getMessage());
                   }}哪位高手帮忙指点下错误````小弟感激不尽

解决方案 »

  1.   

    xxy是什么呀?你到底连的是什么数据库啊?其他应该没什么问题,数据库驱动写错了吧?
      

  2.   

    xxy是数据源名称啊``那个没错吧``就是提示try那有错``
    搞的我莫名其妙
      

  3.   

    如果是try块里面错误,将Exception范围改小为ClassNotFoundException
    如果是这个异常,就是你的classpath中没有这个驱动
      

  4.   

    只能说没语法错误了public class bean {
        Connection Con = null;    public bean() {
            BuildConnection();
        }    public void BuildConnection() {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Con = DriverManager.getConnection("jdbc:odbc:xxy", "sa", "");        } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }    public Connection getConnection() {
            if (Con == null)
                BuildConnection();
            return this.Con;
        }    public void close() {
            try {
                Con.close();
                Con = null;
            } catch (SQLException e) {
                System.out.println(e.getMessage());
            }
        }    public String checkd(String username, String password) {
            String pass = null;
            try {            Statement stm = Con.createStatement();            String sql = "select   password   from   dl   where   name='"
                        + username + "'";
                ResultSet rs = stm.executeQuery(sql);
                if (rs == null)
                    return ("请输入用户名!");
                if (rs.next()) {
                    pass = rs.getString(2);
                }        } catch (SQLException e) {
                System.out.println(e.getMessage());
            }
            if (pass.equals(password))
                return ("登录成功!");
            else
                return ("密码错误!");    }}
      

  5.   

    晕``4个错误``它说的try那是非法的表达试开始```
    高手些帮我调试一下嘛``拜托了
      

  6.   

    另外修改了一处逻辑错误
    while (rs.next()) → if (rs.next())
      

  7.   

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    这句话怎么没有对象呀,只是一个表达式,你把你要定义的类加在前面就OK了!!!
    这样试试:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
      

  8.   

    需要class或interface````try那报的``
      

  9.   

    还有checkd函数那行```报的非法的表达试开始
      

  10.   

    是你自己写的太混乱了,没有良好的编程习惯。
    后面那个try模块有逻辑错误。自己好好分析一下。还有后面try模块里的String pass是没有初始化的变量,可能会报空指针错误。
    建议改为String pass=null;
      

  11.   

    你close()方法下面的那个try 写在方法外面了..肯定有错啊
      

  12.   

    import java.io.*;
    import java.util.*;
    import java.sql.*;public class bean {
    Connection Con = null; public bean() {
    BuildConnection();
    } public void BuildConnection() {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Con = DriverManager.getConnection("jdbc:odbc:xxy", "sa", ""); } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    } public Connection getConnection() {
    if (Con == null)
    BuildConnection();
    return this.Con;
    } public void close() {
    try {
    Con.close();
    Con = null;
    } catch (SQLException e) {
    System.out.println(e.getMessage());
    }
    } public String checkd(String username, String password) {
    try {
    String pass=null; Statement stm = Con.createStatement();
    String sql = "select   password   from   dl   where   name='"
    + username + "'";
    ResultSet rs = stm.executeQuery(sql);
    if (rs == null)
    return ("请输入用户名!");
    while (rs.next()) {
    pass = rs.getString(2); }
    if (pass.equals(password))
    return ("登录成功!");
    else
    return ("密码错误!"); } catch (SQLException e) {
    System.out.println(e.getMessage());
    return "";
    }
    }}
      

  13.   

    我用“冬瓜”的程序修改了一下,测试通过了,你的select语句只到了一个列值,pass = rs.getString(2)有错,改成pass = rs.getString(1)就可以了,我把库连接变了,你自己改回来看看吧import   java.sql.*; public class pp {
        Connection Con = null;    public pp() {
            BuildConnection();
        }    public void BuildConnection() {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Con = DriverManager.getConnection("jdbc:odbc:wd", "system", "manager");        } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }    public Connection getConnection() {
            if (Con == null)
                BuildConnection();
            return this.Con;
        }    public void close() {
            try {
                Con.close();
                Con = null;
            } catch (SQLException e) {
                System.out.println(e.getMessage());
            }
        }    public String checkd(String username, String password) {
            String pass = null;
            try {
                Statement stm = Con.createStatement();
                String sql = "select aa from wdtest where aa='" + username + "'";
                ResultSet rs = stm.executeQuery(sql);
                if (rs == null)
                    return ("Please insert user name!");
                if (rs.next()) {
                    pass = rs.getString(1);
                }        } catch (SQLException e) {
                System.out.println(e.getMessage());
            }
            if (pass.equals(password))
                return ("OK!");
            else
                return ("password error!");    }
        
        public static void main(String[] args){
         pp z = new pp();
         String info = z.checkd("test", "test");
         System.out.println(info);
         z.close();
        }
    }
      

  14.   

    try{     
    String   pass; Statement   stm=Con.createStatement(); 
     public   String   checkd(String   username,String   password) //try都没完,你就来个函数,肯定报非法表达式错误落!悲哀