Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Controller
- public class HomeController {
- public static void main(String args[]){
- }
- Hi hi=new Hi();
- @RequestMapping(value = "/")
- public String home(){
- return hi.getHello();
- }
- @RequestMapping(value="/form")
- public String form(){
- return "form";
- }
- @RequestMapping(value="/end") //method = RequestMethod.GET
- public String end(HttpServletRequest request, HttpServletResponse response) throws SQLException {
- String DB_URL = "jdbc:postgresql://127.0.0.1:5432/postgres";
- String USER = "postgres";
- String PASS = "1234";
- System.out.println("Testing connection to PostgreSQL JDBC");
- try {
- Class.forName("org.postgresql.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("PostgreSQL JDBC Driver is not found. Include it in your library path ");
- e.printStackTrace();
- }
- System.out.println("PostgreSQL JDBC Driver successfully connected");
- Connection connection = null;
- try {
- connection = DriverManager
- .getConnection(DB_URL, USER, PASS);
- } catch (SQLException e) {
- System.out.println("Connection Failed");
- e.printStackTrace();
- }
- if (connection != null) {
- System.out.println("You successfully connected to database now");
- } else {
- System.out.println("Failed to make connection to database");
- }
- Statement statement=connection.createStatement();
- statement.executeUpdate("CREATE TABLE IF NOT EXISTS message (id SERIAL PRIMARY KEY , text CHAR(30) NOT NULL) ;");
- String s=null;
- request.getParameter(s);
- if (s!=null) {
- PreparedStatement preparedStatement=connection.prepareStatement("INSERT INTO message (text) VALUES (?);");
- preparedStatement.setString(1,s);
- }
- return "end";
- }
- }
Add Comment
Please, Sign In to add comment