JAVA操作MSSQL的小问题
publicResultSetselect(Stringsql){try{rst=st.executeQuery(sql);returnrst;}catch(SQLExc...
public ResultSet select(String sql) {
try {
rst = st.executeQuery(sql);
return rst;
} catch (SQLException ex) {
close();
System.out.println("查询失败");
}
close();
return null;
}
main{
String passwordText=new String(password.getPassword());
String sql="select * from table_1 where id like'"+ID.getText()+"'"+"and password like'"+passwordText+"'";
select(sql);
}
数据库已连接好,怎样在table_1中获取id=ID.getText(),password=passwordText的用户的name?//table_1中有name的这列
上面这样哪里错了? 展开
try {
rst = st.executeQuery(sql);
return rst;
} catch (SQLException ex) {
close();
System.out.println("查询失败");
}
close();
return null;
}
main{
String passwordText=new String(password.getPassword());
String sql="select * from table_1 where id like'"+ID.getText()+"'"+"and password like'"+passwordText+"'";
select(sql);
}
数据库已连接好,怎样在table_1中获取id=ID.getText(),password=passwordText的用户的name?//table_1中有name的这列
上面这样哪里错了? 展开
展开全部
1.sql注意空格:
String sql = "select * from table_1 where id like '"+ID.getText()+"' and password like '"+passwordText+"'";
2.返回的对象为ResultSet,你可以用getString("name")获取到这个用户的name
比如:
ResultSet rs = seletc(sql);
String name = rs.next()?rs.getString("name"):null;
String sql = "select * from table_1 where id like '"+ID.getText()+"' and password like '"+passwordText+"'";
2.返回的对象为ResultSet,你可以用getString("name")获取到这个用户的name
比如:
ResultSet rs = seletc(sql);
String name = rs.next()?rs.getString("name"):null;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询