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 trialJason Anders
Treehouse Moderator 145,860 PointsHibernate and ConnectionBuilder
Maybe I've just been staring at this too long, but I'm positive what I'm entering is correct. Please find the tiny (and probably silly) error that I'm making.
I keep getting "Bummer! You haven't properly called the withJdbcVendor
method on the ConnectionBuilder
object."
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 ConnectionBuilder()
.withJbdcVendor("sqlite")
.withDb("languages")
.withUser("th_user", "mysuperlongpassword");
}
}
2 Answers
Jennifer Nordell
Treehouse TeacherHey you! Long time no type
Here's a couple of things. And one is tiny tiny tiny. You transposed two letters. Also, you need to call the build method on your newly made Connection
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 ConnectionBuilder()
.withJdbcVendor("sqlite") //That's jdbc... not jbdc as you've written
.withDb("languages")
.withUser("th_user", "mysuperlongpassword");
c.build(); // Call me to build the connection!
}
}
karthik Vaithi
1,379 PointsHad same error but was getting the String values wrong and it works now when I corrected the String values. Where was I supposed to derive those data from? Fairly certain I didn't see them in the question.
Talking about - sqlite, languages, th_user, mysuperlongpassword
SANTIAGO MARTINEZ
4,226 PointsIt was already given under the comment line:
// TODO: User the builder here instead Connection c = new Connection("sqlite","languages","th_user","mysuperlongpassword"); }
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsYep... knew it was going to be something simple. And I was hoping you'd find it for me.
I did have the build() call there and then I didn't and then I did... I even copy/pasted the names... but... Think maybe time to call it a day. Lol.
Thank you so much!!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherJason Anders You're quite welcome! It's a rare privilege to be able to help you out... for once