在java中如何进行在一个方法里从键盘输入一个数,在另一个方法里也能使用???急急急
做ATM模拟机,在键盘输入卡号,在数据库中进行查询,让输入的这个卡号,在同类里的其他方法(selectyue)也能够使用。publicclassimplenentconn...
做ATM模拟机,在键盘输入卡号,在数据库中进行查询,让输入的这个卡号,在同类里的其他方法(selectyue)也能够使用。
public class implenentconn {
static Scanner sc = new Scanner(System.in);
/**
* 查询进行登录验证
* */
public void select_id(String a) {
Connection conn = Myconnection.getcon();
Statement state = null;
ResultSet rs = null;
System.out.println("请输入卡号:");
a = sc.next();
System.out.println("请输入密码:");
String b = sc.next();
String sql = "SELECT k_id,uname,upass,money,zhuangtai FROM ka where k_id='"
+ a + "'";
.
.
.
/**
* 进行余额查询
* */
public void selectyue(String a) {
String sql = "SELECT k_id,money FROM ka WHERE ka='"+a+"'";
Connection conn = Myconnection.getcon();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
System.out.print("账户余额为:");
while (rs.next()) {
System.out.print(rs.getString("k_id") + ",");
System.out.print(rs.getString("money") + ",");
System.out.println(rs.getString("zhuangtai") + ",");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
Myconnection.closeConn(rs, null, state, conn);
}
}
}
该咋写呢?我传了一个a,但是没传到! 展开
public class implenentconn {
static Scanner sc = new Scanner(System.in);
/**
* 查询进行登录验证
* */
public void select_id(String a) {
Connection conn = Myconnection.getcon();
Statement state = null;
ResultSet rs = null;
System.out.println("请输入卡号:");
a = sc.next();
System.out.println("请输入密码:");
String b = sc.next();
String sql = "SELECT k_id,uname,upass,money,zhuangtai FROM ka where k_id='"
+ a + "'";
.
.
.
/**
* 进行余额查询
* */
public void selectyue(String a) {
String sql = "SELECT k_id,money FROM ka WHERE ka='"+a+"'";
Connection conn = Myconnection.getcon();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
System.out.print("账户余额为:");
while (rs.next()) {
System.out.print(rs.getString("k_id") + ",");
System.out.print(rs.getString("money") + ",");
System.out.println(rs.getString("zhuangtai") + ",");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
Myconnection.closeConn(rs, null, state, conn);
}
}
}
该咋写呢?我传了一个a,但是没传到! 展开
展开全部
可以在类里放一个成员变量存这个号码。示例:
public class Implenentconn {
private String cardNo = null;
public void selectId(String a) {
this.cardNo = sc.next();
}
public void selectYue(String a) {
String sql = ... + this.cardNo + ...;
}
public void logOut {
this.cardNo = null;
}
}
TableDI
2024-07-18 广告
2024-07-18 广告
当我们谈到Python与Excel的拆分时,通常指的是使用Python的库来读取Excel文件中的数据,然后根据某种逻辑(如按行、按列、按特定值等)将数据拆分成多个部分或输出到新的Excel文件中。上海悉息信息科技有限公司在处理这类任务时,...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询