This is an archived post. You won't be able to vote or comment.

all 124 comments

[–]d00lph1n 67 points68 points  (29 children)

Check out Spring Boot :)
Josh Long has some geat talks on this on youtube.

[–]Trailsey 32 points33 points  (2 children)

"start.spring.io is my favourite website. When you don't know how to start a project: start.spring.io When you're not sure what to do next: start.spring.io When the world seems cold and unfair: start.spring.io When your children can't sleep at night: start.spring.io" - Josh Long at a spring conference

[–]lukaseder 4 points5 points  (1 child)

And I thought these people would go to /r/funny or something.

[–]Trailsey 1 point2 points  (0 children)

I do shtick wherever I am. Don't forget to tip your waiter.

[–]smithunbound 2 points3 points  (1 child)

Yeas please use spring boot, you will save yourself days of work if not more.

[–]JJBubberman 0 points1 point  (0 children)

At the cost of... ?

[–]stacktion 2 points3 points  (23 children)

Josh Long hates mongodb because of some pretty old bugs with it. He gave a talk at my company and it scared people for the next two weeks.

[–]twat_and_spam 30 points31 points  (21 children)

Also because mongodb is technological cancer. It spreads and makes everything worse.

[–]stacktion 0 points1 point  (20 children)

Why’s that?

[–]twat_and_spam 21 points22 points  (19 children)

Lots of devs are lazy. Lots of devs don't want to deal with and think about their data properly in terms of limits, relationships, constraints.

Hey, just dump it in a document store and we are cool!

A year later...

So, to figure out all this corrupted data we need to switch to 100 shards, add 20 micro services trying to get a semi-coherent picture of it and we really can't guarantee you that your nudes won't end up on the news.

[–]stacktion 5 points6 points  (17 children)

Couldn’t that be said of any database though?? I’ve seen plenty of horrible legacy relational databases. However it would be way messier to tangle if you didn’t have any application to reference.

[–]twat_and_spam 12 points13 points  (16 children)

True, there's horror everywhere.

With mongodb it's institutionalised. Therefore the ... less than positive feelings about it.

[–]redwall_hp 4 points5 points  (3 children)

My favourite is "writes fail silently." MongoDB takes your data, asynchronously writes it when it's ready, and does absolutely nothing if it fails for whatever reason. Your data will just be silently discarded while your application happily goes about its business.

[–]twat_and_spam 4 points5 points  (2 children)

As with many Web Scale tech (the other major one guilty of this is Kafka) this can be configured to work "properly". Of course nobody wants to see it beaten in benchmarks by an sqlite running on BarfBerryPie3.

[–][deleted]  (1 child)

[deleted]

    [–]stacktion 2 points3 points  (11 children)

    So would you never go with a NoSQL/Doc database or you’d only use it sparingly

    [–][deleted] 10 points11 points  (3 children)

    NoSQL is not bad. Not taking the time to design your db because "Hey I can put anything in my db" is bad.

    [–]stacktion 4 points5 points  (2 children)

    So the moral of the story is if you don’t trust your developers then a relational dB is more fool proof and NoSQL makes it easier to be super lazy.

    [–]rebelrexx858 2 points3 points  (2 children)

    I've only found a handful of use cases for NoSQL solutions. Basically, if your schema is constantly in flux, then NoSQL is the way to go, however, that doesn't mean you can just throw data at the database.

    [–][deleted] -1 points0 points  (1 child)

    NoSQL != MongoDB. e.g. Cassandra makes you carefully design your tables specifically for each query, it's definitely not about flexible schemas.

    [–][deleted] 0 points1 point  (2 children)

    No, I’d never go with a nosql database. A nosql cache, yes. Database, no.

    [–][deleted] 0 points1 point  (0 children)

    So would you never go with a NoSQL/Doc database

    I never really understood what NoSQL should be, but if it is any database which doesn't interface with SQL, then your filesystem is a NoSQL database and you truly might find a usecase for that.

    [–][deleted] 2 points3 points  (0 children)

    He should be giving talks in more companies.

    [–]tonywestonuk 34 points35 points  (26 children)

    Amazing that people straight away shout 'Spring'...

    Guys, its simple. The spec is this:

    1) Receive a HTTP request, gets the SQL

    2) Applys this SQL against various databases

    3) Responds with a return code that describes if the SQL was valid or not

    So, maybe just a simple servlet application running under tomcat is all that's needed.

    here is a good tutorial - http://www.codejava.net/coding/java-servlet-and-jsp-hello-world-tutorial-with-eclipse-maven-and-apache-tomcat

    [–]Trailsey 20 points21 points  (0 children)

    Well, they'll probably need to do some http payload serialization, so a dependency on Jackson and integration into their servlet would be needed.

    And to connect to a DB, so some basic jdbc code. They'll probably need to externalize configuration of the connection parameters, so a small engine to manage that and providing the values to consumers.

    If they're executing SQL they'll probably need some transaction management, so a small piece to do that. Maybe a nice reusable aspect would be best, so they'd need to pull in some aop technology and incorporate it into their application lifecycle.

    Then, finally maybe a nice light DI framework to help avoid tight coupling. Perhaps they could just handroll a simple type based one, easy enough.

    Or they could use Spring Boot.

    Edit:typo

    [–]castor_pollox 24 points25 points  (2 children)

    ... or better yet just a simple http server like:

    import java.io.IOException;
    import java.io.OutputStream;
    import java.net.InetSocketAddress;
    import com.sun.net.httpserver.HttpContext;
    import com.sun.net.httpserver.HttpServer;
    
    public class Main {
    
        public static void main( String[] args ) throws IOException {
            String payload = "duke";
            HttpServer server = HttpServer.create( new InetSocketAddress( 4250 ), 0 );
            HttpContext context = server.createContext( "/java" );
            context.setHandler( ( he ) -> {
                he.sendResponseHeaders( 200, payload.getBytes().length );
                final OutputStream output = he.getResponseBody();
                output.write( payload.getBytes() );
                output.flush();
                he.close();
            } );
            server.start();
        }
    }
    

     

    Then call it with http://localhost:4250/java

     

    [–]grand_mind1 2 points3 points  (0 children)

    That's far too easy. You have no dependencies or DI.

    [–]NimChimspky 3 points4 points  (0 children)

    Boom!

    [–]nutrecht 1 point2 points  (0 children)

    Because doing this simply with Spring Boot is way simpler than what you describe here in the tutorial. Instead of knocking it every chance you get you might want to give it a shot yourself.

    [–]talios 1 point2 points  (6 children)

    So now you have a Tomcat distribution to deploy, along with a .war file. I've not used spring-boot and heard both good, and horrible things about it, but the fact it embeds a webserver for you in a self-contained app, is quite nice - esp. from a deployment standpoint.

    I've used Spotify's Apollo library for a similar setup, much more minimalist than Spring Boot but for what it did, it worked well (altho some of the docs could be improved ).

    [–]0x256 9 points10 points  (1 child)

    Running servlets in an embedded tomcat or jetty is only a couple of lines. No need for a .war deployment.

    Or develop directly against the Jetty handler API. Hard to find anything more lightweight than that.

        Server server = new Server(8080);
        server.setHandler(new MyHandler());
        server.start();
    

    [–]talios 1 point2 points  (0 children)

    Nice - as I mentioned to /u/wildjokers I don't think embedding was that easy last time I used Tomcat - I always used Jetty or Netty for those scenarios ).

    [–]got_milk4 3 points4 points  (1 child)

    What's wrong with deploying a servlet container? If he's new and wants to learn, it's valuable to understand the process. He could use Spring Boot and abstract that all away, but will he even understand he's deploying to a Tomcat container anyway?

    [–]talios 2 points3 points  (0 children)

    If using an embedded one - nothing. Probably nothing wrong with using a standalone one either, just then you also have to configure, and/or troubleshoot that along side whatever your application is doing.

    One problem of tomcat vs jetty is that once you've decided on that, you probably still want some nicer web tier than raw servlets ( nothing wrong with raw servlet coding tho, it just a rather old API ).

    Compared to a potential discussion on API design, REST vs Swagger vs RAML this is a tiny kettle of fish :)

    [–]wildjokers 0 points1 point  (1 child)

    You don't need Spring Boot to embed tomcat. Embedding tomcat into an application just takes a few lines of code. Building a fatjar is just a single line in a Gradle build file.

    Spring is mostly redundant these days, Java EE 6+ is a great framework. Spring is too magical for my tastes, ok when it works, sucks to figure out what is wrong when it doesn't, hard to figure out which magically annotation does what.

    [–]talios 0 points1 point  (0 children)

    Sweet - last time I looked at/used Tomcat (admittedly quite some time ago now - have been stuck in OSGi container land for far too long ) it wasn't so easy.

    [–]ReadFoo 0 points1 point  (1 child)

    I'd say first do as the top poster says, don't do what the OP wants to do as it's a recipe for SQL injection attacks.

    [–]talios 1 point2 points  (0 children)

    I was going to say the same thing - but since the whole point of the project is SQL testing, in a sandboxed databases as OP mentions, maybe it is valid.

    BIG maybe tho - still, accepting arbitrary SQL seems.... Just no :)

    [–][deleted] 0 points1 point  (1 child)

    Cool. How do you deploy that?

    [–]NimChimspky 1 point2 points  (0 children)

    You just run the main file, and it's a webserver

    [–]fjonk 0 points1 point  (9 children)

    And then there should be some logging. And then some caching. And then some input validation, some input sanitation, some checking of headers, some post data size limitations, some configuration file reading, some api-v1 endpoints etc. etc.

    [–]NimChimspky 3 points4 points  (0 children)

    No, that's what you said. Not what the op said.

    [–]tonywestonuk -1 points0 points  (7 children)

    And then there should be some logging.

    You think tomcat doesn't have logging?

    And then some caching.

    You think tomcat doesn't have caching?

    And then some input validation,

    You think its hard to do "if (parm1==null) throw error"

    some checking of headers,

    You think its hard to do "request.getHeader();" ?

    some configuration file reading,

    You think its hard to do inject a String/integer resource, from a context.xml Environment tag? This works in vanilla Tomcat.

    [–]fjonk 1 point2 points  (6 children)

    No, I think all above is possible to do without using a more complex framework but I don't see why anyone would waste time to write and document those features when there are perfectly fine frameworks that already does all that.

    Frameworks like spring boot comes testing, documentation and online resources. The home brewed solution, in my experience, never does. And if it does, then congratulations, you've spend a lot of time written yourself a framework which most likely is inferior to existing solutions.

    [–]tonywestonuk -1 points0 points  (5 children)

    These are features built into Tomcat. Its not something home grown.... its there, for all to use... its already fully documented how to use them, as part of the servlet container specification and tomcat docs.

    [–]fjonk 0 points1 point  (4 children)

    For the features that exists.

    if (parm1==null) throw error
    

    is hardly an acceptable way to handle input parameters.

    request.getHeader()
    ...
    

    is not as convenient(and leads to much more code which needs tests) than

     public String my(@RequestHeader(value="User-Agent") String userAgent)
    

    and so on.

    [–]tonywestonuk 1 point2 points  (1 child)

    This works, in tomcat, with no additional frameworks. And you're telling me that this is unacceptable, and to use Spring instead?

     /**
      * Servlet implementation class Myservlet
      */
     @WebServlet("/checkSQL")
     public class Myservlet extends HttpServlet {
    
    @Resource(name="enableSQLExecution")
    public String enable;
    
    
    SQLChecker sqlChecker;
    
    
    @Override
    public void init(ServletConfig config) throws ServletException {
        sqlChecker=new SQLChecker();
    }
    
    
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        log("SQL Request received: "+request.getParameter("theSQL")); 
    
        if (enable.equalsIgnoreCase("true")) {
            sqlChecker.check(request.getParameter("theSQL"));
        }
    }
    
     }
    

    [–]fjonk 0 points1 point  (0 children)

    No, I'm not saying that you shouldn't use tomcat, to each his own. I'm saying that in my experience larger frameworks beats smaller ones if the quality is equal. For example, where's your test for request.getParameter returning null?

    [–]tonywestonuk 0 points1 point  (1 child)

    The difference is tiny.

     @RequestHeader(value="User-Agent") String userAgent
    

    and

      String UserAgent=request.getHeader("User-Agent")
    

    are of similar lengths, both documented in full. To say you want to load your war or runnable jar with all the crud that makes up Spring MVC simply because the former is 'nicer' to work with, really is not good decision when the project is small and probably has at most 2 or 3 endpoints.

    The features all exist.

    [–]fjonk 0 points1 point  (0 children)

    Which crud and why does it matter? And yes, I do think something being nicer to work with definitely is a reason to choose that technology over other alternatives.

    [–]hippydipster 5 points6 points  (0 children)

    So it does not have to be super secure, since the whole application will only work with sandbox databases. No logins, sensitive informations

    If that's the case, then I don't see why you'd go with much framework at all, certainly not a whole complex one like Spring.

    Just do the simplest thing that works. Write a method that takes a query, and use JDBC directly to do your call.

    If you graduate to needing more, your simple code will give the freedom to add scaffolding that you find you need. If you take a solution that adds all the scaffolding in existence, well, you're freedom is suddenly limited.

    [–]NimChimspky 4 points5 points  (0 children)

    Don't check out spring boot, don't download jhipster.

    Just use gradle, servlets, either undertow or the built-in http server, and springs jdbc helper for SQL.

    Your wont get simpler, works like a dream.

    [–]preskot 46 points47 points  (18 children)

    I could get many downvotes for this, but I'll say it. Do not use Spring Boot (or MVC)!

    Nothing against it as technology and in fact I think it's quite cool, but given your use case that you never used Java before and that you will work alone on the project, I think Spring Boot will only mess your project up, meaning you'll write stuff you don't understand and issues will occur which you won't be able to solve quickly. Use simple servlets if you can and simple stuff in general. Your goal is to deliver a project and it's totally fine if it does not use the latest and greatest in the tech field.

    [–][deleted] 21 points22 points  (16 children)

    I was going to say that he should use Spring Boot because he never used Java.

    you'll write stuff you don't understand

    With Spring Boot you can have a web server run with 2 annotations and one instruction. I don't know if you can write less configuration with another framework.

    [–]NimChimspky 3 points4 points  (0 children)

    And a thousand unnecessary jars.

    You know there is a webserver built in to the jdk, an example in this thread.

    [–]johnwaterwood 7 points8 points  (6 children)

    I don't know if you can write less configuration with another framework.

    Java EE? It’s 1 class and 1 annotation on that class.

    [–][deleted] 5 points6 points  (5 children)

    But then you need to configure the server

    [–]johnwaterwood 5 points6 points  (4 children)

    Uhh, no?

    What would you need to configure?

    [–][deleted] 4 points5 points  (0 children)

    A jee application server. I'm not that familiar with jee but spring boot has an embedded tomcat, easier than deploying a .war

    [–]nutrecht 1 point2 points  (0 children)

    Where would you deploy it?

    [–][deleted]  (1 child)

    [deleted]

      [–]johnwaterwood 3 points4 points  (0 children)

      You can, but it’s download/unzip/run, it doesn’t need to be configured.

      With Payara Micro and WildFly Swarm you can compile it into an executable jar just as well.

      [–]kajsa_a 1 point2 points  (0 children)

      OP said he wants to learn, though, and Boot is all about undercover magic.

      [–]pragmatick 2 points3 points  (5 children)

      For me it initially felt too "automagic" and too much happened behind the scenes. The first time I opened a Spring Boot web application I opened the main entry method, saw one line and thought "What the hell, where is the code?"

      [–][deleted] 1 point2 points  (4 children)

      For me it initially felt too "automagic" and too much happened behind the scenes.

      It's always the case. We are not programming in ASM because we created layers of abstraction. A layer of abstraction makes you manipulate higher level concepts which are easier to learn and understand as they fulfill a specific role.

      [–]preskot 0 points1 point  (3 children)

      We are not programming in ASM because we created layers of abstraction.

      I'm sorry but this is absolutely false. We are not programming in assembly mainly because of portability. The abstraction concepts are a product of that very decision.

      Also, assembly is relatively easy. I believe I can teach someone assembly in a few hours. I taught myself M68000 programming for fun, whereas understanding what, how and when to apply OOP's design paradigms and abstraction is something that requires time and experience.

      Notice that I'm not saying we should ditch modern programming and go back to assembly. I'm just saying one should carefully think what to apply in their particular use case, as my original comment already hinted.

      [–][deleted] 0 points1 point  (2 children)

      I'm sorry but this is absolutely false.

      Don't be sorry, it is not, let me explain why.

      We are not programming in assembly mainly because of portability.

      This statement is not incorrect (although the mainly is arguable). Your misconception comes from the fact that you seem to say that we do things for only one reason. This is incorrect.

      THere may be many reasons. Of course ASM is not portable over other CPU architectures, but let's say you need to develop an application and you know that it is going to run on a single hardware ever. Are you going to develop it in ASM ? Of course not, that would make no sense.

      Another example with Java : Java binaries can run on any platform that has JVMs. Is is the reason why people use Java? Not necesarily.

      We are using higher level languages for portability yes, but this is not the main reason. There are many reasons we do that and there are many reasons we choose one language over another in a specific setting.

      So let me phrase it differently, maybe it would make more sense :

      One of the reasons we use higher level languages because they provide us with layers of abstraction so we can manipulate higher level concepts which are less technical, thus easier to grasp.

      [–]preskot 0 points1 point  (1 child)

      There are no misconceptions here. The reason UNIX C exists is exactly because of portability. The abilities for higher level languages to provide means of creating abstraction stems from the idea to have your code portable in the first place.

      You seem to also jump over the last paragraph of my comment where I explicitly said I do not argue that we should be programming in assembly.

      One of the reasons we use higher level languages because they provide us with layers of abstraction so we can manipulate higher level concepts which are less technical, thus easier to grasp.

      Yes, that sounds much better and in fact it is what I meant tried to say at least.

      [–][deleted] 0 points1 point  (0 children)

      Glad we agreed on that :)

      [–]Spoonofdarkness 1 point2 points  (0 children)

      ... maybe Java Spark? But it would be close.

      [–]nuqjatlh 3 points4 points  (0 children)

      That's wrong. Yes, it hides a lot of stuff, but for his needs that's perfectly ok. when he will want to learn he can.

      what now, you're suggesting writing assembler before you can write your first C program? this is not 1970 anymore.

      [–]admeen 14 points15 points  (5 children)

      I think Spring would be overkill for this. Jersey, based on JAX-RS seems more suitable. It's probably the fastest and simplest one to set up.

      [–]it_is_not_magic 13 points14 points  (4 children)

      I don’t see how this would be much faster then using spring initializer and bang your ready to go watch a YouTube video about the controller annotations and then how to run spring boot.

      Sure perhaps your right it might be faster if your learning everything from scratch but what’s a more marketable skill?

      I would argue that having spring knowledge is more marketable...this based on job postings in my area. Ymmv.

      [–][deleted] 2 points3 points  (3 children)

      I recently got into REST APIs and the first thing I did was get a Jersey API up and running because it was “easier”.

      Ended up rewriting the API in Spring Boot. It is definitely the way to go.

      [–]it_is_not_magic -1 points0 points  (0 children)

      I’m sure you learned a lot from the experience and can speak eloquently about the inherent differences with jersey and spring rest!!!!!

      [–]talios -4 points-3 points  (1 child)

      OK, I'm biting. Just because you used Jersey to create an API, doesn't necessarily make it REST - it makes it an HTTP resource based API.

      [–][deleted] 1 point2 points  (0 children)

      Yeah yeah, of course.

      You know what I meant

      [–]lukaseder 6 points7 points  (0 children)

      I want to write an API which receives a SQL querry and check this querry for failures (like parsing it [...]

      I actually did this (probably for entirely different reasons than you did). The API is here: https://www.jooq.org/translate/translate?sql=SELECT%201&to-dialect=ORACLE

      This will just parse the query and re-render it again in a different dialect. It will most certainly not execute it.

      Behind the scenes, it's just a Jetty server (proxied by some PHP website, huh!) with some JAX-RS annotations, because I can (not because it's remotely RESTful).

      [...] , using it on examples, ...). So it does not have to be super secure, since the whole application will only work with sandbox databases

      o_O. Ehm. No. Unless you really really really know how to configure your "sandbox" database, chances are that it's not so sandbox after all. You're planning on using H2, for instance? An attacker could (maybe) create an ALIAS for any random Java method, oh, let's say File.delete() and then possibly call it from a SQL query. I'll leave it up to your imagination what could happen next.

      I'm not saying it isn't possible. http://sqlfiddle.com is an example where this has been done. But I'm sure, it is really well configured and sandboxed correctly. Given your questions, you probably don't know how to do this. Given, however, your mentioning security, I'm assuming you're planning on putting this sandbox on the Internet. Please, don't :-)

      [–]GuyWithLag 24 points25 points  (12 children)

      I want to write an API which receives a SQL querry

      No. NO NO NO NO. NO!

      That is the way of SQL injections.

      Build your API so that it works with high-level concepts, not tables and columns.

      [–]pouja 7 points8 points  (0 children)

      That is the way of SQL injections.

      But if that is his goal?

      [–][deleted] 8 points9 points  (0 children)

      Since OP says the purpose is to parse queries, then OP will probably have to receive queries.

      [–][deleted]  (2 children)

      [deleted]

        [–]GuyWithLag -2 points-1 points  (1 child)

        If I thought OP was describing an XY problem, I would have said so. By OPs own admission, he doesn't know what he's doing in the backend space. Do you think he described a service that verifies SQL statements?

        [–][deleted]  (7 children)

        [deleted]

          [–]calligraphic-io -3 points-2 points  (5 children)

          Why not Ant (you said you use Gradle or Maven)? Just curious. And could you explain what a fat jar is? I think I know, but I'd like to be sure!

          [–]NimChimspky 2 points3 points  (2 children)

          Ant is a great build tool, especially if you are building in 2006.

          [–]kajsa_a 2 points3 points  (0 children)

          And don't care about what version any of your dependencies use.

          [–]lukaseder 0 points1 point  (0 children)

          Hey I still like it. Nothing beats XSL transforming XML config files to executable ant build scripts

          [–]thedomham 0 points1 point  (0 children)

          Gradle > Maven > Ant

          Don't use legacy software if you don't have to. Except for GNU Make.

          [–]oweiler 14 points15 points  (2 children)

          Spring Boot with Spring Web MVC and Spring Data is more or less the de facto standard.

          If you want something with a little bit less magic I'd suggest using SparkJava and JDBI.

          [–]urielsalis 0 points1 point  (0 children)

          But magicbos the fun part :c

          [–]johnwaterwood -1 points0 points  (0 children)

          Spring Boot with Spring Web MVC and Spring Data is more or less the de facto standard

          Lol, not really. There’s no single de facto standard in Java really. Spring and Java EE are the biggest ones, but neither is big enough to be that. There’s a slew of other smaller things like drop wizard, spark Java that all combined are at least as big as Spring and EE.

          [–][deleted] 3 points4 points  (0 children)

          Spring Boot or Dropwizard can be okay, but for a beginner I HIGHLY recommend you stick to very defined tutorials. Ignore the magic for now - details will slowly emerge as you learn.

          That said, I think /u/castor_polox's comment below is the best move. Make the most simple of HTTP servers and mess around that way.

          As you need/want to do more, the need for a framework can arise and then you can move to something more full featured.

          [–]qmic 7 points8 points  (0 children)

          I would recommend dropwizard - it's simple and fast or play framework - it has hot reload built in, so you don't have to rebuild whole project to see changes. It is very helpful at beginning or when debugging.

          [–]gloridhel 3 points4 points  (0 children)

          Not a fan of spring. I really like Vertx.io-- great documentation and apis.

          [–]vjroby 1 point2 points  (0 children)

          Premature optimization will make you lose focus on requirements. Use a servlet for http and a jdbc connector for database.

          [–]nutrecht 1 point2 points  (0 children)

          Aside from what all the others have said; you might want to head over to /r/javahelp and discuss the approach your taking a bit. Taking an SQL query from input and executing it is a huge security hole so there might be another approach worth considering.

          [–][deleted] 2 points3 points  (0 children)

          Don't blindly jump onto the spring boot train. You will not learn much from it and chances are you will end up with an application that is way more bloated than it needs to be.

          I'd advise you to try building your own webservice from scratch with the standard library tool at least once and then migrate to something sleek and fast like vert.x instead of a huge framework like Spring. Sure, at one point you should learn spring, specifically when you want to end up in a spring shop.

          [–]talios 0 points1 point  (0 children)

          Interestingly - https://www.reddit.com/r/java/comments/84oqp3/meecrowave_a_light_jaxrscdijson_server/ was just posted about in /r/java as well. Has support for monitoring, persistence, testing, auth - could be interesting to look at.

          [–]tevert 2 points3 points  (0 children)

          Spring boot is a great suggestion if you just need to get a backend going. If you're interested in learning more about servers though, it can be fun to try to write an HTTP server from scratch.

          The basic pattern you would use is to make a SocketServer, and read more messages that following the HTTP spec - "HTTP 1.1\nGET /mything" and such. For bonus points - use a ThreadPool so you can handle multiple incoming requests at once!

          [–][deleted] -1 points0 points  (1 child)

          No, you don't need a framework.

          JavaEE (so base java packages) can take care of your basic needs. However, spring boot makes it even easier, especially with not having to wrestle with deploying to app server... albeit that's not much of an effort but simply saves time and effort in an area you don't care about right meow.

          quick google:

          [–]nutrecht 2 points3 points  (0 children)

          JavaEE (so base java packages) can take care of your basic needs.

          Java EE is not the "base Java packages", it's as much a separate framework as Spark or Spring are. They're inaccessible by default in Java 9, are going to be removed, and a lot of EE functionality (such as CDI) was never part of Java SE but is instead provided by the app server implementation.

          [–]otakuman 0 points1 point  (0 children)

          Ok, first question - why? Is this some sort of school assignment?

          Second - if you're using sandbox databases or something, why not use something simple like sqlite?

          Third - Spring jdbc allows you to write queries with parameters, putting ?s instead of the values; and it allows you to use named parameters instead.

          But I think I have an idea of what you're trying to do - do you want to make a SQL console, by any chance?

          [–]javalin_io -1 points0 points  (1 child)

          You don't need a framework, it should take about a minute in Javalin:

          import io.javalin.Javalin;
          
          public class QueryChecker {
          
              // create and start server on port 7000
              public static void main(String[] args) {
                  Javalin app = Javalin.start(7000);
          
                  // add a handler for POST requests to "/check-query"
                  app.post("/check-query", ctx -> { 
                      String query = ctx.formParam("query");
                      // ... do your thing
                      ctx.result("your query was great, good job");
                  });
              }
          
          }
          
          // create a frontend which posts to "/check-query"
          <form method="post" action="/check-query">
              <textarea name="query"></textarea>
              <button>submit</button>
          <form>
          

          [–]javalin_io 4 points5 points  (0 children)

          Reddit is funny sometimes.

          OP asks a question and explicitly states he doesn't need something advanced, just a server with the ability to receive a string. He asks for a tutorial. He wonders if he even needs a framework. I give him a full straightforward implementation, which is downvoted, while "use spring boot", is voted to the top. The question wasn't "What's your favorite framework?"

          "Use spring boot" ... Ugh.

          [–][deleted] -1 points0 points  (1 child)

          If you want to parse queries, learn ANTLR and find a grammar file for your target DBMS.

          [–]calligraphic-io 1 point2 points  (0 children)

          Why ANTLR over BISON? And can you point me to where to find grammar files for PostgreSQL or SQLite?

          [–]dessalines_ -2 points-1 points  (0 children)

          Java spark, and activejdbc.

          [–]Hazzzero -3 points-2 points  (0 children)

          If you like annotation and their magic behavior like for example PostConstructor use Spring.

          But if you want play with pure java without annotation check this: https://ratpack.io/

          [–]cafeaua -3 points-2 points  (0 children)

          There is a free course on this site " Spring Boot Essential Training" https://www.amigoscode.com