Connecting to MYSQL Database in Java

Ads
 

Connecting to MYSQL Database in Java

I've tried executing the code below but the error that I get is "Error: com.mysql.jdbc.Driver" I downloaded the connection driver and configured the class path but the error persists. Please please help here coz I have tried to locate the problem but I can't find it. In addition to that, I have switched off the firewall just in case it is blocking the connection but there is no change. import java.sql.*; public class jdbctestcon { public static void main(String args[]) { System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost/"; String dbName = "textbook"; String driver = "com.mysql.jdbc.Driver"; String userName = "root"; String password = ""; try { Class.forName(driver).newInstance(); conn = DriverManager.getConnection(url+dbName,userName,password); System.out.println("Connected to the database"); conn.close(); System.out.println("Disconnected from database"); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } } }

View Answers

October 4, 2011 at 10:50 AM

Do you have mysql-connector-java-5.0.8-bin.jar file in jdk lib? If not then put it.

For more information, visit the following link:

JDBC MySQl Connectivity


October 4, 2011 at 2:21 PM

I have mysql-connector-java-5.1.17-bin.jar. Does the version really matter? I copied the connector to jdk lib and also configured the CLASSPATH to match the the location of the driver in the jdk lib, but still the error that I still get is "com.mysql.jdbc.Driver". What could be missing here?

Ads









Related Tutorials/Questions & Answers:
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code...("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost/"; String dbName = "textbook"; String driver
Connecting to a MySQL Database in Java
Connecting to a MySQL Database in Java   ... will learn how to connect the MySQL database with the Java file. Firstly, we need... on connecting to a MySQL database, after going through this program you
Advertisements
Null pointer exceptation-Java Servlet web application,Problem connecting with MYSQL database
Null pointer exceptation-Java Servlet web application,Problem connecting with MYSQL database  Hi everyone i would like to ask few question here.... T_T I have develop my java web application in window Environment and now i
Connecting code of reset password to database
Connecting code of reset password to database  connecting code of reset password to database
java connecting frames
java connecting frames  how to connect one frame to another frame by using awt or swings?`print("code sample
Connecting to remote mysql server using jdbc.
Connecting to remote mysql server using jdbc.  How to Connect to remote mysql server using jdbc
code for connecting reset password code to database.
code for connecting reset password code to database.  code for connecting reset password code to database.   Hello Friend, Do you want to change your password and update the password to database
java connecting to oracle db
java connecting to oracle db  PLZ SAY ME HOW TO INSERT THE VALUES INTO ORACLE THIS IS THE CODE: import java.io.*; import java.sql.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import
jsp -sevlet connecting to database using dropdown
jsp -sevlet connecting to database using dropdown  How can I get my dropdown list from oracle database and then submit it to another table in JSP. I... to the database and fetches an array of strings from a database table and then sends
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  how to send data from mysql database to google chart api using java
MYSQL Database
MYSQL Database  Can any one brief me about how to use MYSQL Database to store the create new database, create tables. Thanks.   Hi, the MySQL database server is most popular database server and if you want to know
Connecting to MySQL database and retrieving and displaying data in JSP page
MYSQL Java Connector Library
for MySQL required for connecting Java and MYSQL Database Server. You can download... and MYSQL database. Downloading Java SDK and MYSQL server is not sufficient to create a database application in Java. You will also required a MYSQL Java
Connecting to the Database Using JDBC and Pure Java driver
update mysql database
update mysql database  update mysql database
java code for threading example for connecting data base
java code for threading example for connecting data base  Write a program that has two threads First thread queries the database and fetches all the employee records from the emp table. Stores the employee objects
Create Database and tables in MySQL
and tables in MySQL Database? Explain me step-by-step as I am beginner in MySQL. Thanks   Hi, First of all you have to connect to MySQL database through command line tool. Connecting to MySQL Database: mysql -uroot -p Here
how to retrieve image from mysql database using java and show it in HTML img tag ?
how to retrieve image from mysql database using java and show it in HTML img tag ?  how to retrieve image from mysql database using java and show it in HTML img tag
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  Добовляйтесь в группу "МАЙНКРАФТА" Будьте участниками Группы Помогаите нам и себе Наша группа https://vk.com/club60851464 Есть свой сервер! Хорошая атмосфера
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
Creating a MySQL Database Table to store Java Types
Creating a MySQL Database Table to store Java Types... to create a table in MySQL database that stores all java types. Here we... to establish the connection between MySQL database table and java file. After
XML parsing to Mysql database
XML parsing to Mysql database  Can someone please post the code for parsing an XML file into Mysql database using SAX
Java and MySQL
Java and MySQL   I am doing a project on an accounting system. I need to know to things: How do I write reports using information in an MySQL database . How get multiple MySQL database rows and assign them to variables r
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
How To Store Multilple Images In MySQL database dynamically with image... Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
Insert Image into Mysql Database through Simple Java Code
Insert Image into Mysql Database through Simple Java Code... simple java code that how save image into mysql database. Before running this java code you need to create data base and table to save image in same database
Mini project on Book Bank using netbeans tool with java and for database using mysql
Mini project on Book Bank using netbeans tool with java and for database using mysql  hi roseindia, i have need the miniproject on bookbank with the deisgn using the netbeans tool, and create the database for that using mysql
Mini project on Book Bank using netbeans tool with java and for database using mysql
Mini project on Book Bank using netbeans tool with java and for database using mysql  hi roseindia, i have need the miniproject on bookbank with the deisgn using the netbeans tool, and create the database for that using mysql
connecting databases
connecting databases  I need to connect mysql on 2 or more remote pc'c. how can i giv the ip address for 2 or more systems. is it possible to connect to the required systems by user specifying the database and table name my
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array  i am using netbeans 7.0 ,with struts 1.3.8 and i want to insert multiple images in mysql database ,with use
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
Java and Mysql
Java and Mysql  Sir, I want to connect my java program with mysql server (mysql server is situated on another windows machine ) ??? ???? ?????   Put mysql jar file in your jdk lib and set the classpath. After

Ads