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
August 7, 2012 at 4:09 PM
add mysql-connector-java-5.0.8-bin.jar in your class path
Related Tutorials/Questions & Answers:
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
java runtime error: JDBC code - Java Beginnersjava 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 need a help in this pleasei 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 codePlease 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 codePlease 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 <
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 - JDBCDatabase 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 codei 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 codei 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 - JDBCerror 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 help me to give code - Java Beginnersplease 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
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 Beginnersplease 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 Beginnersplease 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 Beginnersplease 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
database connectivity using jsp codedatabase 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 mysqldatabase 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
HTML code to servlet to database using jdbcHTML
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