Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-17-2008, 06:48 AM
Member
 
Join Date: Feb 2008
Posts: 1
nancyv is on a distinguished road
problem in connecting to mysql database
Hi all
I tried to run the following code..to connect to the database but getting Exception: com.mysql.jdbc.Driver....

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class dataservlet extends HttpServlet {



public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
int emid=0;
PrintWriter out = resp.getWriter();
resp.setContentType("text/html");

String url = "jdbc:mysql://localhost/shipment";

String query = "SELECT user_id FROM tbl_user";


try {

Class.forName("com.mysql.jdbc.Driver").newInstance ();


Connection con = DriverManager.getConnection(url,"nancy","");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery (query);

while(rs.next())
{
emid=rs.getInt("user_id");
}
out.println(emid);

rs.close();
stmt.close();
con.close();

}

catch (SQLException ex) {

out.println ("SQL Exception: " + ex.getMessage());


}

catch (java.lang.Exception ex) {


resp.setContentType("text/html");
out.println ("Exception: " + ex.getMessage ());
}

}


}

I cannot connect to the database at all..I have created the database and tables correctly...Please help in finding my mistake...Thank you
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-02-2008, 07:56 AM
Member
 
Join Date: Aug 2007
Posts: 5
cheeryTomato is on a distinguished road
Maybe you can try to change the class driver for this one and see whether it can solve the problem:
Class.forName("org.gjt.mm.mysql.Driver");

If still doesn't work, you can try to set the jdbc using the ip address instead of localhost and see whether it works or not.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-26-2008, 12:47 PM
Member
 
Join Date: Mar 2008
Posts: 13
geeta_ravikanti is on a distinguished road
where u r doing the program actually from console or Eclipse editor
If its from console may be the calss path connection
u just verify classpath is set corectly or not to u realted jar file
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-02-2008, 09:40 AM
Member
 
Join Date: Mar 2008
Posts: 13
geeta_ravikanti is on a distinguished road
connection from servlet to database
Me also getting the same problem
Did u get the solution how u relove u r problem
Please tell me how did u solve that
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-02-2008, 12:16 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
Have you checked the sqljdbc.jar (JDBC driver) is set correctly in the classpath??
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-02-2008, 12:32 PM
Member
 
Join Date: Mar 2008
Posts: 13
geeta_ravikanti is on a distinguished road
I sovel my problem
thnQ for the reply

I solved my problem some one suggets add the ojdbc14.jar file into web-inf\lib directory then i got the ans correctly
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-02-2008, 12:33 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
Brilliant! Nice one.

Can you please now mark this thread as Solved. Thank you.
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
connecting to a database mxb7642 Database 2 08-20-2008 06:59 PM
Connecting to a database peiceonly New To Java 2 04-06-2008 03:28 PM
Problem with jTable that is binded with a table in MySQL Database rajkenneth NetBeans 0 03-29-2008 04:36 PM
Problem connecting to my Database using Java javaneed New To Java 3 08-13-2007 10:35 AM
connecting to mysql database javagal NetBeans 2 08-04-2007 01:36 PM


All times are GMT +3. The time now is 10:57 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org