Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class QueryTesting
- {
- public static void main(String[] args)
- {
- try
- {
- // create a java mysql database connection
- Class.forName("com.mysql.jdbc.Driver");
- try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/?verifyServerCertificate=false&useSSL=true", "username", "password")) {
- Statement s = null ;
- try {
- s = conn.createStatement();
- } catch (SQLException ex) {
- Logger.getLogger(QueryTestingForWMC.class.getName()).log(Level.SEVERE, null, ex);
- }
- int Result ;
- try {
- Result = s.executeUpdate("USE myDatabase");
- } catch (SQLException ex) {
- Logger.getLogger(QueryTestingForWMC.class.getName()).log(Level.SEVERE, null, ex);
- }
- PreparedStatement preparedStmt= null;
- // create the java mysql update preparedstatement
- String query = "update relativesTable set idRelativeMembers = ? , Name = ? , Picture = ? , RelationDegree = ? , persons_idPersons = ? where idRelativeMembers = ?";
- // create the mysql update preparedstatement
- preparedStmt = conn.prepareStatement(query);
- preparedStmt.setString(1,"00002/10");
- preparedStmt.setString(2,"عبد الحفيظ أحمد عبد الفتاح الدؤري");
- preparedStmt.setBinaryStream(3, null);
- preparedStmt.setString(4, "إبن عم");
- preparedStmt.setString(5, "00002");
- preparedStmt.setString(6, "00002/10");
- // execute the preparedstatement
- preparedStmt.executeUpdate();
- // execute the java preparedstatement
- preparedStmt.executeUpdate();
- preparedStmt.close();
- s.close();
- }
- catch (Exception e)
- {
- System.err.println("Got an exception! ");
- System.err.println(e.getMessage());
- }
- }catch (ClassNotFoundException e)
- {
- System.err.println("Got an exception! ");
- System.err.println(e.getMessage());
- }
- }
- }
- // the mysql update statement
- String selectedMemberPrimaryKey = getMembersWithoutPhotos().get(jTable5.convertRowIndexToView(jTable5.getSelectedRow())).getId() ;
- System.out.println("This is an update query");
- String updateStatement = "update relativesTable set idRelativeMembers = ? , Name = ? , Picture = ? , RelationDegree = ? , persons_idPersons = ? where idRelativeMembers = ?";
- // create the mysql update preparedstatement
- preparedStmt = conn.prepareStatement(updateStatement);
- preparedStmt.setString(1, jTextField2.getText());
- // the mysql insert statement
- System.out.println("This is an insert query");
- String updateStatement = "insert into relativesTable (idRelativeMembers, Name, Picture, RelationDegree, persons_idPersons) values ( ?, ?, ?, ?, ?)";
- // create the mysql update preparedstatement
- preparedStmt = conn.prepareStatement(updateStatement);
- preparedStmt.setString(1, jTextField2.getText());
Add Comment
Please, Sign In to add comment