• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jdbc

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to get a compiled test program to work but i get this in the output pane...
com.mysql.jdbc.Driver
Press any key to continue.

I think that means my driver is not setup right.
I can access the database in the mysql Command Line Cleint all right.
this is under system props\Environment Variables at the bottem (WinXP)
System Variables... under Variable is this... database
under Value is this... .;C\mysql\mysql-connector-java-3.1.11-bin.jar


is the right setup???
roba
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are reading a little much into the output. It says press any key to continue. Is there any mention of an error?
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I see what you are saying but than it doesn't do anything. Does my values look right?
Could it be the url, user or password?
roba
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rob armstrong:
OK I see what you are saying but than it doesn't do anything. Does my values look right?
Could it be the url, user or password?
roba



You haven't given any samples of code, error messages, or your URL. What does your test program do? What is it supposed to do?

You are asking an unanswerable question based on the information provided
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob along with this thread you hijacked two other threads with this request.

http://faq.javaranch.com/view?PatienceIsAVirtue and http://faq.javaranch.com/view?TellTheDetails

You say you are having a problem yet you have provided almost no information whatsoever. Post your test code. Post the results. If all you say is you don't think it works because it doesn't do anything that is meaningless. Maybe it isn't supposed to do anything. Maybe you aren't actually running the program. Maybe it is actually hanging/crashing/etc and you haven't noticed or who knows what.

Nobody can guess. So please stop posting requests in mulitiple threads and focus on delivering INFORMATION in this thread that could actually make your question answerable.

So please if want help there are many experts here who can help you but you need to post ALL your code along with an explanation of what it does or doesn't do.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deleted those posts in other threads that Max alluded too. Let's continue discussion here with the aforementioned information.
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.sql.*;
import java.text.NumberFormat;

public class ListMovies
{
public static void main(String[] args)
{
NumberFormat cf=NumberFormat.getCurrencyInstance();
ResultSet movies=getMovies();

try
{
while (movies.next())
{
Movie m=getMovie(movies);
String msg=Integer.toString(m.year);
msg +=": "+m.title;
msg +=" ("+cf.format(m.price) + ")";
System.out.println(msg);
}
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
}

private static ResultSet getMovies()
{
Connection con=getConnection();
try
{
Statement s=con.createStatement();
String select="Select title, year, price "+"from movie order by year";
ResultSet rows;
rows=s.executeQuery(select);
return rows;
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
return null;
}
private static Connection getConnection()
{
Connection con=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/movies";
String user="root";
String pw="daytek";
con=DriverManager.getConnection(url,user,pw);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
System.exit(0);
}
catch (SQLException e)
{
System.out.println(e.getMessage());
System.exit(0);
}
return con;
}

private static Movie getMovie(ResultSet movies)
{
try
{
String title=movies.getString("Title");
int year=movies.getInt("Year");
double price=movies.getDouble("Price");
return new Movie (title, year, price);
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
return null;
}
private static class Movie
{
public String title;
public int year;
public double price;

public Movie(String title, int year, double price)
{
this.title=title;
this.year=year;
this.price=price;

}
}
}
Sorry for not posting anything very direct. This is a COMPILED code that i can't get to work. I have a active database on my computer right now as well.
when i run the code the black box pops up and gives me this...

com.mysql.jdbc.Driver
Press any key to Continue....

I think my driver is setup wrong and if so I would like to ask help with that part of it. Or I am entering the wrond URL or something
Thank You
roba
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please put mysql.jar in the path "jdk1.4\jre\lib\ext" ,and restart.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ideally u shud not put any jar file inside ur jdk/lib.. ,unless the jar name contains the word java.
comming back to ur problem..try following ,
Extract the mysql.jar inside web-inf\classes of ur appication and try executing the ur class.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aarati appears to have a problem with typing (we prefer real words and not abbreviations, please) but I agree. While you could put the jar there, it is not the best place for it. For one thing it would prevent you writing code for more than one MySQL version at a time, and if you forgot you placed the jar there you'd have an awful time trying to work out what was wrong.
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

com.mysql.jdbc.Driver
Press any key to Continue....

I think my driver is setup wrong and if so I would like to ask help with that part of it. Or I am entering the wrond URL or something
Thank You
roba



You sill have not identified that there is even a problem. The code you posted does not under any circumstances produce that output. Perhaps you running in an IDE with breakpoints or something I do not know and could only guess at.

Then elsewhere you say it is the compiled version which produces this message. So I am beginning to suspect that the real issue is that you don't know anything about Java.

Roba, many people are willing to help you but you have to help us help you. Please post a SIMPLE piece of code that demonstrates an actual connection to and disconnecting from a MySQL server. Then please run that code and tell us the output if any.

Others may wish to play 21,000 questions as to what might be wrong with your classpath but as up to this point I see nothing that actually says ClassNotFound I am not convinced that that will ever be helpful.
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry Max this is the only output i get when i execute the code. There really isn't much more to say other than i do not understand how to setup the drivers properly. I can execute queries on mysql client on that database and it works fine doing things that way so i could only assume I did not setup the classpath properly so it wont connect.
roba
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think i have the mysql.java file or the path that it should go in for that matter. Am I missing something?
roba
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running this code in your IDE? How are you running this code? The code posted WILL NOT produce the output you say on it's own so something else is saying press any key to continue.

You may well have a problem with your classpath. But even if you do we are stuck until we know how you are running it anyway because you aren't invoking java directly. There is some middle layer of some sort... probably an IDE.
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok here is something i found out....
catch (ClassNotFoundException e)
this is where it is getting the output from.
it throws this and puts the output. Why is it not finding it?
roba
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rob armstrong:
ok here is something i found out....
catch (ClassNotFoundException e)
this is where it is getting the output from.
it throws this and puts the output. Why is it not finding it?
roba




The jar with the driver is not in your classpath. How you need to fix this depends on how you are running.
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After reding the tutorial and a couple books with some brief stuff I still can't figure it out. Ill try and to the odbc way and see if i can get that way to work
Thanks roba
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rob armstrong:
Ill try and to the odbc way and see if i can get that way to work


People generally have more problems getting ODBC to work with Java than JDBC; not less. Maybe you'll be a happy exception...
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stu would you or anybody have time to work with me on msn messenger some day with setting it up?
Once i have it running i will be fine.
roba
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic