Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try{
- Class.forName("com.mysql.cj.jdbc.Driver");
- String USERNAME = "root";
- String PASSWORD = "root";
- String CONN_STRING = "jdbc:mysql://localhost:3306/javaddy?serverTimezone=UTC";
- Connection connection = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);
- try{
- int incrementID = increment();
- String pass = in;
- System.out.println(pass);
- PreparedStatement pstmt = connection.prepareStatement("INSERT INTO inquiries (LearningMat_ID,Inquiry_ID,Inquiry_question,Inquiry_answer)VALUES (?,?,?,?)");
- pstmt.setInt(1,0);
- pstmt.setInt(2, incrementID);
- pstmt.setString(3, pass);
- pstmt.setString(4, null);
- pstmt.execute();
- //
- bot("Your query has been forwarded to the database. An admin will answer it later.");
- connection.close();
- }catch(SQLException e){
- System.out.println(e);
- }
- }catch(ClassNotFoundException | SQLException e){
- System.out.println(e);
- }
- }
- public int increment() throws SQLException
- {
- int id = 1;
- Statement stmt = null;
- ResultSet rs = null;
- try{
- Class.forName("com.mysql.cj.jdbc.Driver");
- String USERNAME = "root";
- String PASSWORD = "root";
- String CONN_STRING = "jdbc:mysql://localhost:3306/javaddy?serverTimezone=UTC";
- Connection connection = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);
- try{
- String query = "SELECT MAX(Inquiry_id) from inquiries";
- stmt = connection.createStatement();
- rs = stmt.executeQuery(query);
- while(rs.next())
- {
- id = rs.getInt(1) +1;
- }
- }catch(SQLException e){
- System.out.println(e);
- }finally{
- connection.close();
- }
- }catch(ClassNotFoundException | SQLException e){
- System.out.println(e);
- }
- return id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement