Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC 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.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vicky amrev
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.
4 Answer(s)      2 years and 3 months ago
Posted in : JDBC


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)


Advertisement
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
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
Advertisements
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
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
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
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
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
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
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 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
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
JDBC - Java Database Connectivity Tutorial
JDBC - Java Database Connectivity Tutorials  ...; New Features in JDBC 4.0 Java database connectivity (JDBC) is the Java... Java and JDBC Learn how to access database using JDBC.   Enhanced
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
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
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
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
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
JDBC Connectivity Code In Java
JDBC Connectivity Code In Java      ... in understanding JDBC Connectivity Code in Java. In this program, the code...;url = "jdbc:mysql://localhost:3306/";   
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 <
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... driver as per your application needs. About JDBC Java Database Connectivity
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
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
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me   Hi have develop the jsp to populate related birds whenever we give input in the text field. But i am getting the wrong
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 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
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
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
 

 

 

DMCA.com