java的类中
String id="200905232323";
String a="id";
我想通过a获取到id的值。也不知道大家能明白的我的意思没。
就是我知道一个变量的值id为“200905232323”,但是我设了一个变量a,通过字符串处理我能知道a为id,我现在是想获得“200905232323”,但是不能直接用id获取
各位大虾帮忙!
String id="200905232323";
String a="id";
我想通过a获取到id的值。也不知道大家能明白的我的意思没。
就是我知道一个变量的值id为“200905232323”,但是我设了一个变量a,通过字符串处理我能知道a为id,我现在是想获得“200905232323”,但是不能直接用id获取
各位大虾帮忙!
String a=id; System.out.print("真的不清楚你想做什么...");
Java codeString id="200905232323";
String a=id;
System.out.print("你在干什么啊??");
可是一个id是变量,另一个却是字符串。
String id="200905232323";
String a="id";
a肯定得不到id的值。因为两个字符串的值不一样。。如果你是说 你不能直接访问id 想通过a来取得id的值的话,那么id应该是一个有限制的变量吧,否则你这样访问的毫无意义啊,
String id="200905232323";
String a=id; 你可以这样写,但是我觉得意义不大 因为,其实 id和a的值是一样的,,另外 实在不知道 你说的不能直接访问id。是什么意思。。
public class Test
{
public String id="200905232323";
public String a="id";
public static void main(String[] args)
{
try
{
Test t = new Test();
java.lang.reflect.Field f = t.getClass().getDeclaredField(t.a);
System.out.println((String)f.get(t));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
String username="careers";
String userpassword="111111";
String sql="insert into Person(id,username,password) values ('"+id+"','"+username+"','"+userpassword+"')"; 我的意思是要组装出这样一个sql语句,但是我不想通过字符串拼接的方法,因为用到的地方很多。
我通过正则表达式能把INSERT INTO [dbo].[JobSeekerInfo]
([ID]
,[UserName]
,[UserPassword])
VALUES
({@id}
,{@userName}
,{@userPassword})中需要替换为值的变量名id,userName,userPassword取出来。但是我要把{@id}替换为‘111’...现在大家明白我的意思了吧!
9楼的意思是对的。但是 public String a="id";必须定义为全局的吗?这个值我必须通过传递过来啊!这个方法没用过,所以恳请您能还能再细致一点,万分谢谢!
String sql = "UPDATE [dbo].[jobKnowledge] SET [title] = {@title} ,[content] = {@content} ,[lastUpdate] = getDate() WHERE [ID] = {@id}";
//todo:将{@title}替换为title的值;将{@content}替换为content的值;将{@id}替换为id的值。通过正则表达式"\\{\\@(\\w)+\\}"可以匹配出其中的{@title};{@content};{@id}";
return sql;
}
也不知道表述清楚了没有,做毕业设计,用到的地方很多,所以不想通过拼接的方法实现。希望大虾们能指点一哈,万分感谢!
用过没有?
Connection con = null;
Boolean bool=false;
try {
Class.forName(driver);
con = DriverManager.getConnection(url);
PreparedStatement pstmt;
pstmt = con.prepareStatement(sql);
pstmt.setString(1, userName);
pstmt.setString(2, password);
ResultSet rs = pstmt.executeQuery();
bool = rs.next();
} catch (ClassNotFoundException ex) {
Logger.getLogger(SQLServer.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (SQLException ex) {
Logger.getLogger(SQLServer.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
return bool;
}
这个用过啊!我知道了,可以通过这种方法实现!呵呵,谢谢楼上的。但是用我想的那种也应该能够实现吧!
{
Connection con = ConnectionManager.getConnection();
Statement st = null;
PreparedStatement ps = null;
ResultSet rs = null;
try
{
ps = con.prepareStatement(“update tbl_user set name=?,address=?,age=? where id=?”);
ps.setString(1,"username");
ps.setString(2,"你住在哪里啊");
ps.setInt(3,55);
ps.setLong(4,"1001");
//ps.setTimestamp(9,new Timestamp(ng.getDT_EXPIRATION().getTime()));
ps.executeUpdate();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
//关闭连接
} }
String sql = "UPDATE [dbo].[jobKnowledge] SET [title] = {@title} ,[content] = {@content} ,[lastUpdate] = getDate() WHERE [ID] = {@id}";
//todo:将{@title}替换为title的值;将{@content}替换为content的值;将{@id}替换为id的值。通过正则表达式"\\{\\@(\\w)+\\}"可以匹配出其中的{@title};{@content};{@id}";
return sql;
} todo就是我要实现的功能