Connection conn;
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
conn = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\MUHAMMAD SHAHAB\\STUD1.accdb");
String username = tf.getText();
String password = String.valueOf(pf.getPassword());
PreparedStatement pst;
pst = conn.prepareStatement("INSERT INTO SUN (Username,Password)" + "values(?,?)");
pst.setString(1, username);
pst.setString(2, password);
我只想在数据库中输入整数数据而不是字符串。如何在此代码中用int替换字符串?我应该使用哪种方法从TextField
获取整数数据。
答案 0 :(得分:0)
编辑:添加了从字符串到int的转换。
使用:
//if the data is an integer represented as String
String intAsString = "5";
//convert it. catch NumberFormatException exceptions
int intValue = Integer.parseInt(intAsString);
//update
pst.setInt(3, intValue);