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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![lassek](https://secure.gravatar.com/avatar/bfd327edafd74f2fb70238d9889fc71f?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
lassek
8,209 PointsQuiz seems flawed
I fail to understand why I get a "Bummer" on this exercise...when I try it in IntelliJ, it builds and runs just fine. Printing out the Connection object also works fine if I do that - seems there's a flaw in this exercise?
package com.teamtreehouse.builder;
public class Connection {
private String jdbcVendor;
private String dbName;
private String username;
private String password;
public Connection(String jdbcVendor, String dbName, String username, String password) {
this.jdbcVendor = jdbcVendor;
this.dbName = dbName;
this.username = username;
this.password = password;
}
public Connection(ConnectionBuilder builder) {
this.jdbcVendor = builder.jdbcVendor;
this.dbName = builder.dbName;
this.username = builder.username;
this.password = builder.password;
}
public static class ConnectionBuilder{
private String jdbcVendor;
private String dbName;
private String username;
private String password;
public ConnectionBuilder(){}
public ConnectionBuilder withJdbcVendor(String jdbcVendor) {
this.jdbcVendor = jdbcVendor;
return this;
}
public ConnectionBuilder withDb(String dbName) {
this.dbName = dbName;
return this;
}
public ConnectionBuilder withUser(String username, String password) {
this.username = username;
this.password = password;
return this;
}
public Connection build() {
return new Connection(this);
}
}
}
import com.teamtreehouse.builder.Connection;
import com.teamtreehouse.builder.Connection.ConnectionBuilder;
public class Application {
public static void main(String[] args) {
// TODO: User the builder here instead
Connection c = new Connection.ConnectionBuilder()
.withJdbcVendor("sqlite")
.withDb("languages")
.withUser("th_user","mysuperlongpassword")
.build();
}
}
1 Answer
![KRIS NIKOLAISEN](https://secure.gravatar.com/avatar/65d74a723997b41a80d2d909c6e06960?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
KRIS NIKOLAISEN
54,969 PointsIt says to use the builder instead. So if you remove connection:
Connection c = new ConnectionBuilder()
lassek
8,209 Pointslassek
8,209 PointsYes that makes it accept the answer, thanks. I was using the builder in my answer as well though, but referencing it from the Connection class. It's unnecessary since the code has already imported the builder to use directly, but I feel it should be accepted as a correct answer anyway?