Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Endpoints

I have receive this :Exceptionorg.sql2o.Sql2oException: Could not acquire a connection from DataSource

public class App { public static void main(String[] args) { String connectionString = "jdbc:h2:~/reviews.db:INIT=RUNSCRIPT from 'classpath:db/init.sql"; Sql2o sql2o = new Sql2o(connectionString, "", ""); CourseDao courseDao = new Sql2oCourseDao(sql2o); Gson gson = new Gson();

    post("/courses", "application/json", (req, res) -> {
        Course course = gson.fromJson(req.body(), Course.class);
        courseDao.add(course);
        res.status(201);
        res.type("application/json");
        return null;
    } , gson::toJson);

    get("/courses", "application/json", (req, res) -> courseDao.findAll(), gson::toJson);

    get("/courses/:id", "application/json", (req, res) -> {
        int id;
        id = Integer.parseInt(req.params("id"));
        // TO DO: What if this not found
        Course course = courseDao.findById(id);

        return null;
    });

    after((req, res) -> {
        res.type("application/json");
    });
}

}

Seth Kroger
Seth Kroger
56,413 Points

Could you share the code you're working on? The connection string can be quite touchy about formatting.

I copy-pasted the main class

3 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

I read some other posts & people with this error solved it by:

  • restarting computer
  • check for a file called $appname.xml & see if its correct

Dont know if this will help you, but passing along

It didn't work with the restart, but thanks :)

found the problem, I've put ":" instead of ";". wrong : String connectionString = "jdbc:h2:~/reviews.db:INIT=RUNSCRIPT from 'classpath:db/init.sql"; correct :String connectionString = "jdbc:h2:~/reviews.db;INIT=RUNSCRIPT from 'classpath:db/init.sql'";