CLANNADZY 2013-12-18 15:29 采纳率: 0%
浏览 2408

JAVA数据库连接程序跳过某段代码执行了

检查密码是否正确的Checkpasswd类
[code=java]package com.qdgxy.sql;

import java.sql.SQLException;

public class Checkpasswd extends SQL_connection{
private static int i =0;
//select count(*) from consumer where consumer_password='12345678' and exists(
//select * from consumer where consumer_no=00001 )
//final String querystatement="select "+s1+" from "+s2;

    public static void query(String s1,String s2)
    {
        SQL_connection.query(s1,s2);
        System.out.println("query");

/* final String querystatement="select "+s1+" from "+s2;
try {
rs=stmt.executeQuery(querystatement);
} catch (SQLException e) {
e.getMessage();
}*/
}
public static void exe()
{
System.out.println("exe");
try{
i = rs.getInt(1);
System.out.println("exe");
System.out.println(i);
}catch(SQLException e) {
e.getMessage();
}

}
public static int isexist()
{
System.out.println("isexist");
if(i !=0)
return 0;//存在此账户
else
return 1;//不存在此账户
}
}
[/code]

连接数据库的父类SQLException

[code=java]package com.qdgxy.sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SQL_connection {

/**
 * @param args
 * @throws ClassNotFoundException 
 * @throws SQLException 
 */

/**
 * @param args
 */

    // TODO Auto-generated method stub
    final static String Drivername="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    final static String Connection="jdbc:sqlserver://localhost:1433;DatabaseName=LaboratoryDatabase";
    final static String Username="sa";
    final static String Passwd="123";
    protected static Connection conn=null;
    protected static Statement stmt=null;
    protected static ResultSet rs=null;
    public static void classforname()
    {
        try {
            Class.forName(Drivername);
        }catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.getMessage();
        }
    }
    public static void connection()
    {
        try{
             conn=DriverManager.getConnection(Connection,Username,Passwd);
             System.out.println("conn");
             System.out.println(conn);
            }catch(SQLException e){
                e.getMessage();
            }
    }
    public static void statement()
    {
        try {
            stmt=conn.createStatement();
            System.out.println("stmt");
            System.out.println(stmt);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.getMessage();
        }
    }
     public static void query(String s1,String s2)
     //s1代表列名,s2代表表名
     {
         final String querystatement="select "+s1+" from "+s2;
         try {
                rs=stmt.executeQuery(querystatement);
                System.out.println("rs");
                System.out.println(rs);
            } catch (SQLException e) {
                // TODO Auto-generated catch block 
                e.getMessage();
            }
     }
     public static  void exe()
     {

/* try{
while(rs.next())
{
String s1=rs.getString(1);
System.out.println(s1);
}
}catch(SQLException e) {
e.getMessage();
} /
}
public static void close()
{
System.out.println("close");
try {
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}[/code]
[code=java]btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
String name=text.getText();
String passwd=text_1.getText();
final String s1="count(
)";
final String s2="consumer where consumer_password='"+passwd+"' and exists(select * from consumer where consumer_no='"+name+"');";
Checkpasswd.classforname();
Checkpasswd.connection();
Checkpasswd.statement();
Checkpasswd.query(s1,s2);
Checkpasswd.exe();
Checkpasswd.close();
if(Checkpasswd.isexist() ==0)
{
System.out.println("new mainmenu");
shell.dispose();
new Mainmenu();

            } 
            else{
                create_worrymessagebox();
            }
        }
    });[/code]

数据库语言为[code=sql]select count(*) from consumer where consumer_password='12345678' and exists(
select * from consumer where consumer_no=00001 )[/code]
查询结果为(列名)无列名:(值)1

问题是checkpasswd里的[code=java]try{
i = rs.getInt(1);
System.out.println("exe");
System.out.println(i);
}catch(SQLException e) {
e.getMessage();
} [/code]
不执行,达不到我验证密码要求,为什么这段代码程序不执行,很疑惑,下面那些close()却继续执行了

  • 写回答

2条回答

  • 毕小宝 博客专家认证 2015-12-31 01:47
    关注

    你调试过了,这段不执行的代码是不是进入异常分支了呢?你把异常堆栈日志打印出来看看。

    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法