Yu Sasaki's Blog

Icon

プログラミングとか英語とかの練習!

JDBC – using MySQL to make a connection between my local host and remote database

I created a “Student table” last time, and today I learned how to make a connection on Eclipse so I tried doing it.

I was given a code for SELECT statement using ORACLE driver.

My task was to make some modification in the code so that it can establish a connection with the remote host using mysql driver, instead of Oracle one, and successfully process the SELECT statement.

I changed the code like this:

// Invoke the dbQuery method
String driverName = “com.mysql.jdbc.Driver“;
String serverName = “zenit.senecac.on.ca“;
String portNumber = “3306“;
String databaseName = “my_account“;

String url = “jdbc:mysql://” +
serverName + “:” + portNumber
+ “/” + databaseName;

String u = “my_account“;
String p = “my_password“;

String query = “SELECT * FROM  Students“;

SELECT * FROM Students

SELECT * FROM Students

Works fine!

See you!

Advertisements

Filed under: EJB605, Java, Servlets & JSP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: