Java JDBC connectivity. Please see the code below, I am using mysql database also I have configured JDBC drivers. In the end of code Error is also posted for better review. Please Help.

Java JDBC connectivity. Please see the code below, I am using mysql database also I have configured JDBC drivers. In the end of code Error is also posted for better review. Please Help.

JAVA JDBC connectivity problem. I am using MySql database, also I have downloaded and configure JDBC Connector. In the end of this code please see the error that I am getting.

package com.ct;

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException;

public class DbDemoConnection { public static void main(String args[]) throws ClassNotFoundException, SQLException { Connection conn =null; ResultSet rs = null; try{ Class.forName("com.mysql.Jdbc.Driver"); conn = DriverManager.getConnection( "jdbc:mysql://vicky-PC/student"); rs = conn.createStatement().executeQuery("select * from student");

while (rs.next()) { System.out.println(rs.getString("name")); } }catch (ClassNotFoundException cnfEx){ throw cnfEx; }catch (SQLException sqlEx){ throw sqlEx; }finally{ if(rs!=null){ rs.close(); } if(conn!=null){ conn.close(); } } } }

This is the following error I am getting:

Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.Jdbc.Driver at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at com.ct.DbDemoConnection.main(DbDemoConnection.java:13)

View Answers

August 7, 2012 at 12:50 PM

Put mysql-connector-java-5.0.8-bin.jar file in your jdk and jre lib.


August 7, 2012 at 12:52 PM

You have imported wrong driver name. Here is an example:

import java.sql.*;

class RetrieveData 
{
    public static void main(String[] args) throws Exception
    {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from data");

        while(rs.next()){
            String name=rs.getString("name");
            String address=rs.getString("address");
            String contact=rs.getString("contactNo");
            String email=rs.getString("email");

            System.out.println(name+" \t "+address+" \t "+contact+" \t "+email);
            }
    }
}

August 7, 2012 at 1:20 PM

Thank you so much :)


August 7, 2012 at 4:09 PM

add mysql-connector-java-5.0.8-bin.jar in your class path









Related Tutorials/Questions & Answers:
this is my javascript code and i am not understanding the mistake in this,please help me?
this is my javascript code and i am not understanding the mistake in this,please help me?  <html> <h2>Form Validation</h2>...; if((nn1.value==null)||(nn1.value=="")){ alert("Please Enter
I need help on my Java code.... please please help me out!?
I need help on my Java code.... please please help me out!?  Well my... in the file. Also it should be displayed on the screen. However my code doesn't display the anagram on screen or the output file! Please show me whats wrong. Thanks i
Advertisements
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt...."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt...."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
please help me solve this problem when i am create database connection using servlecontext
please help me solve this problem when i am create database connection using servlecontext  hi... I have create a database connection using servletcontext . in this code when i login first time it will exceute sucessfully
Begineer Help Help Please Thanks A million ) I am using Jcreator
Begineer Help Help Please Thanks A million ) I am using Jcreator  System.out.println(" Income Statement...: $ 1.00 Retained Earnings: $ 2.00 I don't know how to sort the array
java runtime error: JDBC code - Java Beginners
java runtime error: JDBC code  Hi i want to insert data into mysql database in my local system. I installed mysql5.0 and using mm.mysql-2.0.4-bin.jar and also set in the class path. the code is compilled and giving runtime error
i want java code for this xml file...please show me..
i want java code for this xml file...please show me..   xbrli:shares xbrli:pure iso4217:INR
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
I am having problem with configuring Hibernate sessionfactory. Please Help
I am having problem with configuring Hibernate sessionfactory. Please Help  Sir, I am having problem with configuring Hibernate sessionfactory.. I was using the old version of Hibernate before now I am using Hibernate 4
i need a help in this please
i need a help in this please  The factorial of a nonnegative integer...) Write an application that computes the value of ex by using the formula ex = 1...=input.nextInt(); long num=m; for(int i=m;i>1;i
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert this php code int java/JSP . if (isset($_POST['orders'])) { $orders...]); $array[] = $item[1]; } } I tried like this (see below JSP code
Please help with this code
Please help with this code  I need some help getting the Search method below to work with the menu, and I also cannot figure out how to get my bubble...(); Student[] students = new Student[numStudents]; for (int i = 0; i <
inheritance....please help me friends...!!!... this is important project that i have to do it..
inheritance....please help me friends...!!!... this is important project that i have to do it..   Point ................. #x : int #y : int... Circle that extends Point class. Refer a figure below to identify the attributes
ajax code please help to solve this........
ajax code please help to solve this.  in this i am trying to get data... null; } please help me when i am running this it show an error... and use ajax onchange but when i am trying to do so it show some error
Database drivers - JDBC
Database drivers  Please give me types of drivers and explain them.... * Native-API, partly Java driver, also called Type 2. * JDBC-Net...-types.shtml Thanks.  Hi! we have four types of drivers. JDBC-ODBC
i am unable to identify the error in my code
i am unable to identify the error in my code  class Program { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter
i am unable to identify the error in my code
i am unable to identify the error in my code  class Program { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter
error in code - JDBC
error in code  hi friends i had one problem when i am running the application of jdbc code it is getting that Exception in thread "main...;Hi friend, Please give details about problem and full code to solve
Please can I get the code for solution of producer consumer problem using semaphores?
Please can I get the code for solution of producer consumer problem using semaphores?  Please can I get the code for solution of producer consumer problem using semaphores?   import java.util.*; class Semaphore
please let me get code how to insert a data to mysql using setter and getter method by using java
please let me get code how to insert a data to mysql using setter and getter method by using java  please let me get code how to insert a data to mysql using setter and getter method by using java pelease let me have the code
please let me get code how to insert a data to mysql using setter and getter method by using java
please let me get code how to insert a data to mysql using setter and getter method by using java  please let me get code how to insert a data to mysql using setter and getter method by using java pelease let me have the code
can i know the error in this code... am unable to run this code
can i know the error in this code... am unable to run this code  ... System.out.println(arr[i]); } }   You have used incorrect symbol in your code like < >. The for is improper and not completed. Moreover, you have
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level...!"); String str = buff.readLine(); int i=1; int j; while(i<=4){ for(j=1;j<=i;j++) System.out.print(str); i=i+1; System.out.println
Please help me to modify my java code from php code
]; } } I tried like this (see below JSP code) ... but this is not giving me the exact result as the above PHP code is giving. So please help me to convert...Modify Java code from PHP Code  i want to covert this php code int
i want to create website,with manu with three level submenu on top side of page please send me code java
i want to create website,with manu with three level submenu on top side of page please send me code java   iam createing wibsite thats using eclipse andtomcat server,please help me to write menu with three level submenu
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops...; k<=4; k++){ System.out.print(k+"|"); for (int i=1; i<=4; i++){ System.out.print(i); } System.out.println
How to update record to database? I have trouble with the following code
How to update record to database? I have trouble with the following code  I have written the update statement but it still not work to update the record,what is the missing of the following code ?I need help,thankyou <?php
JDBC Connectivity Code In Java
JDBC Connectivity Code In Java      ... in understanding JDBC Connectivity Code in Java. In this program, the code...;String url = "jdbc:mysql://localhost:3306/"
could anyone please help with the code.
could anyone please help with the code.  protected void doPost...(request, response); } } could anyone please check the code. If i enter the correct username and password it redirects me to the correct page but if I enter
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
JDBC - Java Database Connectivity Tutorial
JDBC - Java Database Connectivity Tutorials   ... 4.0 Java database connectivity (JDBC) is the Java Soft specification...;      Accessing Database using Java and JDBC Learn
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case...(); } } } ------------------------------- read for more information, http://www.roseindia.net/java/beginners/read
Am i convetrting the code right ? - Java Beginners
(IOException ex) { }// i also tried the code below// try...Am i convetrting the code right ?  C# private void button... a led on it. The LED blinks on the C#'s code. I think the code i have written
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES... applicable on all imported goods at a rate of 5%, with no exemptions. When I purchase items I receive a receipt which lists the name of all the items
I want to update the multiple values of database depending on checkbox..? Please help me out..
I want to update the multiple values of database depending on checkbox..? Please help me out..   Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes
database connectivity using jsp code
database connectivity using jsp code  i have two tables employee...),'bbbb','bbbb'); so this syntax is possible to use in jsp code based... key)this is employee table schema in mysql adduser->(Emp_ID varchar(50),Ename
JDBC, Java Database Connectivity
have in our site roseindia.net. Our website is very famous for JDBC and Java tutorials. Java Database Connectivity or JDBC for short is Java bases API... drivers for major databases. You can download the JDBC driver for your database
database connectivity using mysql
database connectivity using mysql  java file: eg1.java package eg... seconds) I am using Netbeans 5.5, mysql server 5.0, to get data from table student. but while running this code i am getting error as mentioned above
Please tell me the code to generate the below structure
Please tell me the code to generate the below structure  1 2 3 4 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 7 8 9 1 2 8 9 1 9 1 2 8 9 1 2 3 7 8 9 1 2 3 4 6 7 8 9 1 2 3
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly   index.html <...) { e.printStackTrace(); } %> 3)For the above code, we have created following table
The required JDBC drivers to establish connectivity to my database part of the JDK.
The required JDBC drivers to establish connectivity to my database part of the JDK.  Are all the required JDBC drivers to establish connectivity to my database part of the JDK
HTML code to servlet to database using jdbc
HTML code to servlet to database using jdbc  pls send me the code related to the title   Hi Friend, Try the following code:ADS...=DriverManager.getConnection("jdbc:odbc:student","",""); Statement stmt
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....   */ import...++) { System.out.println("Please insert number for element "+ i); double..."); System.out.println("| i. Print the list from a specified index
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...("Please insert number for element "+ i); double element..."); System.out.println("| i. Print the list from a specified index
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...("Please insert number for element "+ i); double element..."); System.out.println("| i. Print the list from a specified index
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...("Please insert number for element "+ i); double element..."); System.out.println("| i. Print the list from a specified index
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....  import...("Please insert number for element "+ i); double element..."); System.out.println("| i. Print the list from a specified index

Ads