这是带有插入功能的UserModel.Class
/bin/sh -c /home/myname/Scrivania/capture.sh
这是调用UserModel的UserController.Class 首先是构造函数和所需的@FXML标记
public boolean isInsert(String userNew, String passNew) throws SQLException{
PreparedStatement preparedStatement=null;
ResultSet resultSet=null;
String query = "INSERT INTO employee (username, password) VALUES (?,?)";
try{
preparedStatement = connect.prepareStatement(query);
preparedStatement.setString(1, userNew);
preparedStatement.setString(2, passNew);
resultSet = preparedStatement.executeQuery();
if(resultSet.next()){
return true;
}else{
return false;
}
}catch(Exception e){
return false;
}finally{
preparedStatement.close();
resultSet.close();
}
}
然后ActionEvent SignUp接受userModel对象并调用 上面提到的isInsert函数
UserModel userModel = new UserModel();
@FXML
private Label userLbl2;
@FXML
private TextField UserField;
@FXML
private PasswordField PassField;
以下是生成的错误 -
public void SignUp(ActionEvent event){
try {
if(userModel.isInsert(UserField.getText(), PassField.getText())){
userLbl2.setText("Your account has been created");
}else{
userLbl2.setText("Your account has not been created");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:0)
最好在控制器类的public class SingleItemView extends Activity {
// Declare Variables
TextView txtdefinition;
TextView txtword;
TextView txtexample;
ImageView imgflag;
String[] definition;
String[] word;
String[] example;
int[] flag;
int position;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.singleitemview);
// Retrieve data from MainActivity on listview item click
Intent i = getIntent();
// Get a single position
position = i.getExtras().getInt("position");
// Get the list of definition
definition = i.getStringArrayExtra("definition");
// Get the list of word
word = i.getStringArrayExtra("word");
// Get the list of example
example = i.getStringArrayExtra("example");
// Get the list of flag
flag = i.getIntArrayExtra("flag");
// Locate the TextViews in singleitemview.xml
txtdefinition = (TextView) findViewById(R.id.definition);
txtword = (TextView) findViewById(R.id.word);
txtexample = (TextView) findViewById(R.id.example);
// Locate the ImageView in singleitemview.xml
imgflag = (ImageView) findViewById(R.id.flag);
// Load the text into the TextViews followed by the position
txtdefinition.setText(definition[position]);
txtword.setText(word[position]);
txtexample.setText(example[position]);
// Load the image into the ImageView followed by the position
imgflag.setImageResource(flag[position]);
}
}
方法中创建一个实例
initialize()