JDBC.Notes__Install and Use the mySQL Connector

JDBC.Notes__Install and Use the mySQL Connector - CST...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CST 365.465, JDBC NOTES, L. Vinakos Download and install the mySQL Connector/J from mysql. This is the JDBC driver for mySQL (mysql-connector-java-5.1.12.zip). a. where to copy the driver In the example below, the database is called "mydatabase". Initializing the Driver and Connecting to mySQL Before we can connect to MySQL, we need to initialize the Connector/J driver. This is done with the static Class.forName( ) method; Class.forName("com.mysql.jdbc.Driver").newInstance(); Then we can then create a Connection object that represents a specific MySQL connection by using DriverManager.getConnection( ) with an appropriately formatted URL. Connection myConnection = DriverManager.getConnection ("jdbc:mysql://localhost:3306/test?user=root&password=secret"); (see example below) The URL for the getConnection( ) method has the following format: jdbc:mysql:// host [: port ]/ [ database ] [? Name1 = Value1 ] Name2 = Value2 ] ... Code for Testing the Database Connections: <testmysql.jsp begin> <%@ page import = "java.sql.*" %> <%@ page import = "java.io.*" %> <% String connectionURL = "jdbc:mysql://localhost:3306/mydatabase?user=;password=";
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

JDBC.Notes__Install and Use the mySQL Connector - CST...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online