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.

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)      a year and 11 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
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
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
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
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
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 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 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
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
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 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 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
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
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
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
when sending the mail from java I am getting the below error - JavaMail
when sending the mail from java I am getting the below error   when sending the mail from java I am getting the below error : Exception...}} at java.net.URLClassLoader.findClass(libgcj.so.7rh) Code
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
Please Provide the direct Downloadable source code for better understanding
Please Provide the direct Downloadable source code for better... clear.* As am a fresher, it is difficult for me to implement the code practically. I kindly request you to please provide the direct downloadable source code so
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
database connectivity in java - JDBC
database connectivity in java  import java.io.*; import java.awt.... images\\collapsed.gif"); l1=new JLabel("Code:"); l2=new JLabel("Name:"); l3=new JLabel("Mobile:"); l4=new JLabel("Email:"); l5=new JLabel("Code
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
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
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
I want code below mention programe
I want code below mention programe  Create a web application using any technology that accepts a keyword and displays 10 relevant tweets from Twitter in real-time for that keyword
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...++) { 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...++) { 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
Advertisements
 

 

 

DMCA.com