Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. byte[] s = DatatypeConverter.parseHexBinary(query);
  2. System.out.println(new String(s, "UTF-8"));
  3.  
  4. byte[] bytes = Hex.decodeHex(query.toCharArray());
  5. System.out.println(new String(bytes, "UTF-8"));
  6.  
  7. @Controller
  8. @RequestMapping("fiddle")
  9. public class MainController {
  10.  
  11. @PostMapping
  12. public ResponseEntity<?> processingQueries(@RequestBody String query) {
  13. System.out.println(query);
  14.  
  15. return new ResponseEntity<String>("Query prcessed successfully.", HttpStatus.OK);
  16. }
  17.  
  18. }
  19.  
  20. import React from 'react';
  21. import TableButton from './TableButton';
  22. import { connect } from 'react-redux';
  23. import PropTypes from 'prop-types';
  24. import { processQueries } from '../actions/queryActions';
  25.  
  26. class Board extends React.Component {
  27. constructor() {
  28. super();
  29.  
  30. this.state = {
  31. query: 'Write here your SQL query...'
  32. }
  33. this.onChange = this.onChange.bind(this);
  34. this.resetField = this.resetField.bind(this);
  35. this.onSubmitRun = this.onSubmitRun.bind(this);
  36. }
  37.  
  38. onChange(e) {
  39. this.setState({ [e.target.name]: e.target.value });
  40. }
  41.  
  42. resetField(e) {
  43. this.setState({ query: '' });
  44. }
  45.  
  46. onSubmitRun(e) {
  47. e.preventDefault();
  48. console.log(this.state.query);
  49. this.props.processQueries(this.state.query, this.props.history);
  50. }
  51.  
  52. render() {
  53. return (
  54. <div className="box flex-stretch">
  55. <div className="blue smallClass">
  56. <TableButton />
  57. </div>
  58. <div className="mediumClass">
  59. <form onSubmit={this.onSubmitRun}>
  60. <textarea
  61. name="query"
  62. className="txtArea"
  63. value={this.state.query}
  64. onChange={this.onChange}
  65. onClick={this.resetField}
  66. rows="27"
  67. >
  68. Write here your SQL queries...
  69. </textarea>
  70. <input type="submit" value="Run" className="runButton"/>
  71. </form>
  72. </div>
  73. <div className="red largeClass">
  74. One of three columns
  75. </div>
  76. </div>
  77. );
  78. }
  79. }
  80.  
  81. Board.propTypes = {
  82. query: PropTypes.string
  83. }
  84.  
  85. const mapStateToProps = state => ({
  86. query: state.query
  87. })
  88.  
  89. export default connect(mapStateToProps, { processQueries })(Board);
  90.  
  91. import { PROCESS_QUERY } from '../actions/types';
  92.  
  93. const initialState = {
  94. query: ''
  95. }
  96.  
  97. export default function(state = initialState, action) {
  98. switch(action.type) {
  99. case PROCESS_QUERY:
  100. return {
  101. ...state,
  102. query: action.payload
  103. }
  104. default:
  105. return state;
  106. }
  107. }
  108.  
  109. import axios from 'axios';
  110. import { GET_ERRORS, PROCESS_QUERY } from './types';
  111.  
  112. export const processQueries = (query, history) => async dispatch =>
  113. {
  114. try {
  115. console.log(query);
  116. await axios.post("/fiddle", query);
  117. history.push("/fiddle");
  118.  
  119. dispatch({
  120. type: PROCESS_QUERY,
  121. payload: ''
  122. })
  123. } catch(error) {
  124. dispatch({
  125. type: GET_ERRORS,
  126. payload: error.response.data
  127. })
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement