Java Database Programming

Programming
Tutor: None Selected Time limit: 3 Days

In Java programimng, how do I use Java Database to connect to a database I have online through a hosting account?

I need to connect and do a select statement to display the data.

Nov 30th, -0001
public Connection getConnection() throws SQLException {

Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", this.userName);
connectionProps.put("password", this.password);

if (this.dbms.equals("mysql")) {
conn = DriverManager.getConnection(
"jdbc:" + this.dbms + "://" +
this.serverName +
":" + this.portNumber + "/",
connectionProps);
} else if (this.dbms.equals("derby")) {
conn = DriverManager.getConnection(
"jdbc:" + this.dbms + ":" +
this.dbName +
";create=true",
connectionProps);
}
System.out.println("Connected to database");
return conn;
}

Check out this page: http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html

Are you using MYSQL?
Jun 19th, 2013

Thanks that looks like the right direction for what I need. I am using MYSQL. 

I'm not sure how to implement your code there. Is that a function already included in Java I need to call or is that something I should copy and paste into my code?

Jun 19th, 2013

Hi, did you check out the link I gave you? You have to write your own functions to connect to the database but JAVA has lots of API for you. say this "DriverManager.getConnection"

Jun 20th, 2013

Okay, I've checked the page several times. I'm just not sure what to do. What do I need to import firstly. Secondly, I put DriverManager.getConnection in my main method.

Then where do I put my function to connect. Do I write it as it's own class or as it's own method. Then after that, what else is missing to make it run? I still have a lot of errors.

Jun 20th, 2013

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Nov 30th, -0001
...
Nov 30th, -0001
Feb 20th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer