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.

 
 


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)      9 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)

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 Pages:
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
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
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
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
Logic error? HELP PLEASE! :(
Logic error? HELP PLEASE! :(  Hello Guys! i have a huge problem. What... the date from mysql using the matched email. First let the user key... have a method to get the date using the email and other method to get its personal
JDBC CONNECTIVITY - JDBC
= con.prepareStatement("insert into detail values(?,?,?,?)"); I am a bigner in Jdbc so please tell me in brief each line code and also tell me please that what is the method... of JDBC drivers. Each driver has to be register with this class. getConnection
connectivity - JDBC
connectivity  I hav MySQL 5.0, JDK 1.5, Tomcat 5.0 in my system when I tried to connect to database and insert data it is showing exeception..., Please check the mysql-connector-java-5.0.6-bin.jar file for Connection
Oracle Database connectivity probem
Oracle Database connectivity probem  hi Below is the code of oracle database connectivity, when i compile it, it will show the error: oracle.jdbc.driver.OracleDriver I am using netbeans 6.5 and tomcat 6.0 and jdk 1.6 i have
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
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
JDBC Training, Learn JDBC yourself
JDBC Connectivity Code in Java.   JDBC Drive For Mysql... JDBC Connection Pooling Accessing Database using Java and JDBC Learn how... Tutorials JDBC (Java Database Connectivity) -Tutorials  JDBC
Types of JDBC drivers
entirely because the non-java interface have the direct access to database... is native code not written in java. 3.The connection occurs as follows... of different environment. 3.The JDBC Client driver written in java, communicates
need help...................please
on this area. Please help me. By the way, I'm using access Database and JSP coding...need help...................please  I have a problem in my JSP Coding... (the name list is also coming from database)every information about the person
Eclipse Connectivity - JDBC
with eclipse 3.4 Genemade with mysql Database. can u please help me to how to do connectivity..and which plugins are required for it. i have try to do connectivity but i got given below error. "Error Occured Error
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
Connectivity with sql in detail - JDBC
Connectivity with sql in detail  Sir/Madam, I am unable to connect the sql with Java. Please tell me in detail that how to connect...; String url = "jdbc:mysql://localhost:3306/"; String dbName
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
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 <
Connecting to MYSQL Database in Java
the following link: JDBC MySQl Connectivity   I have mysql-connector... please help here coz I have tried to locate the problem but I can't find...Connecting to MYSQL Database in Java  I've tried executing the code
Help needed for Form Validation please help!
Help needed for Form Validation please help!  I have created a page which has login as well as Signup fields. I validated the login part by using jsp... clicking the submit button for sign up it also goes through the jsp code and returns
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
Jdbc connectivity by type 4 driver
Jdbc connectivity by type 4 driver  I have done a code with database...) { e1.printStackTrace(); } } } }.....end of code please help me out as soon as possible...i m waiting...and i m using oracle 11g
java database error - JDBC
java database error  hi all i am writing one swing application where i want to insert data into database(MS-Access) but dont know how to do... the following code to insert the data into MS-Access database: import java.sql.
mysql problem - JDBC
mysql problem   hai friends i have some problem with image storing in mysql. i.e while i am using image(blob) for insert the image it says... photos. i have use below code for that. try{ Class.forName(driverName
jdbc connectivity through jsp
jdbc connectivity through jsp  my code: <%@ page language="java... = ""; String url = "jdbc:mysql://localhost/interviewer...; </html> ______________________end of the code
JDBC Components
Database Connectivity. For connectivity with the database we uses JDBC... and retrieve results and updation to the database. The JDBC API is part of the Java... provides JDBC access via ODBC drivers.You have to load ODBC binary code
jdbc front end - JDBC
jdbc front end  a code written using JDBC,ODBC,SQL and swing only that allows the user to select the required driver related to a specific database that can execute the SQL queries related to that database.  Hi Friend
MySQL connectivity - JDBC
MySQL connectivity  hi all, i am not able to connect Mysql to java ..as i connect it ..i am getting the error ..saying classNotFoundException:com.mysql.jdbc.Driver....could anybody help in this regard.....waiting for a reply
jdbc - JDBC
jdbc  How can i store images in a database column without a front end and retrive it using a java program? plz help me with the code.  Hi...: http://www.roseindia.net/jdbc/save_image.shtml Retrieve Image using Java
java error - JDBC
, I saw your posted code. your is currect please add mysql connector jar...java error  Why am I getting errors in the follwing program... = null; String url = "jdbc:mysql://localhost:3306/"; String dbName
JDBC:Runtime error - Java Beginners
should have to follow to execute the program successfully. once again i am posting.... I tried as you said but still i facing the same problem no suitable drivers found for mysql. I copied the mysql-connector-jave-5.0.8-bin.jar, mysql-connector
jdbc mysql - JDBC
=DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","root... this problemm thank u ---------- java ---------- Listing all table name in Database! SDKH... be problem in your mySql, the above code is working fine. first you check
Mysql & java - JDBC
Mysql & java  Hi guys, please help! I'm new to mysql, I want to connect to mysql 5.1 using java. But it shows error about: Class.forName("com.Mysql.Jdbc.Driver").newInstance. Is there something I'm not doing right? Please help
JDBC CONNECTIVITY
but when we run application i have an error message like this..." (""""""Java Tools..."); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/abhi... execution finished."""""") what may the problem?   Java Mysql
help please
help please  hi i am done with register application using jsps... thing i want to imp in my app.please any one have app of this imp pls send me war file.. Or atleast help me with code here.. I tried checking session alive
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
regarding java - JDBC
regarding java  i am making a project on supply chain system i have done front end work using swing and AWT concepts of java i am using mysql as back end and i have also configured java with mysql i am using three table
JDBC Connectivity - JDBC
String filename = "d:/java/mdbTEST.mdb"; String database = "jdbc...JDBC Connectivity  my question is how to connect a Java program with MS-Access database?  Hello Use this code import java.sql.
jdbc oracle connectivity problem
jdbc oracle connectivity problem  Hi All, I am trying to connect my swing application to oracle DB . but class.forname is giving error. Please.... As i connected my struts application with same DB with same code. Thanks
pls review my code - Struts
pls review my code  Hello friends, This is the code in struts. when i click on the submit button. It is showing the blank page. Pls respond soon...("error in connecting database"); } return null
Review
Review  Friends please help e on this How to write java code to display the next question onclicking review button
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
pls review my code - Struts
pls review my code  When i click on the submit page i am getting a blank page Pls help me. thanks in advance. public ActionForward execute...) System.out.println("PLEASE FILL THE FIELDS"); else try
database connectivity
database connectivity  i m trying to connect this servlet with database but i m not able to Code is ot giving any error and there is no update in database plsss somebody can help code is here package newpackage; import
jdbc - JDBC
(); } } } I have written the above code in NetBeans.But it is not working.There are so many errors in it? Please help me out.  Hi friend, Plz specify...."); Connection conn = null; String url = "jdbc:mysql://localhost:3306
JDBC CONNECTIVITY
JDBC CONNECTIVITY  How do i connect my database to java. I have the connector file and i place it in lib of jdk folder and installed the jdbc driver... file in environment variable.   Java Mysql connectivity Other JDBC
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
jdbc - JDBC
jdbc  Hi.. i am running the servlet program with jdbc.... now in this same program i am want to do same thing using second resultset..... i am closing first resultset before opening the second resultset
jdbc - JDBC
management so i need how i can connect the pgm to database by using jdbc...? if u replyed its very useful for me...  Hi, Please read JDBC tutorial... can use following code to connect to Database with the help of JDBC API

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.