|
Write a simple program that does NOTHING but a jdbc connection.
That means that it will NOT have any GUI components.
That means that it will NOT have any Tomcat/JEE specific code.
Set the connection string.
Run it.
Look at the exception.
Most likely causes are incorrect connection string, no access to the database and/or that the database is not running.
Only the first is solvable in java.
|
|
|
|
|
Does the MySQL server run on the same machine? If no, configure it to accept connections from different computers.
Do you want to login as root from a different computer? Also that must be configured.
Have you tried a user with password?
Can you connect to your MySQL server with a MySQL tool, e.g. MySQLAdministrator.exe or MySQLQueryBrowser.exe?
|
|
|
|
|
Yes the Sql server is in a same machine and I have also allowed remote connections and firewall access rules for both Tomcat and MySql.I can easily access MySql from Workbench as well as ping from connection builder tool from eclipse.The problem arises when I use com.mysql.jdbc.Driver in driver name in my code
Always believe in God and never let misfortunes make you give up
|
|
|
|
|
which port do you use? is it already taken? what's the Exception saying?
|
|
|
|
|
Dear fellows! I have tried everything.Made a program in notepad compiled it and when ran ame error then I used this command on elevated command prompt C:\>javap mysql.connector.java-5.1.20 and the result " Class ---- is unavailable".I run MySql over 3306 port it is working jhakass(means great) as i have 4GB RAM and CORE Processors 500 GB HD 32 Bit Win 7 Ultimate
Always believe in God and never let misfortunes make you give up
|
|
|
|
|
adeel1981 wrote: javap
"javap" has nothing to do with compiling nor running a java application.
adeel1981 wrote: Class ---- is unavailable"
Class path problem or class naming problem. Which is a general problem that has nothing specifically to do with JDBC.
|
|
|
|
|
I have tried everything.Made a program in notepad
yeah for sure. Why don't you use a IDE? Eclipse and Netbeans are free, there is no excuse for not using them.
You have NOT tried everything when you are not even using a proper IDE.
|
|
|
|
|
Dude I hav alreasy tried Eclipse 4.2 installed all plugins and softwares,installed tomcat 7.
Always believe in God and never let misfortunes make you give up
|
|
|
|
|
Why do you not address the actual problem you have and investigate why you cannot connect to MySQL? Either your parameters are wrong (you say they are correct) or the driver is not accessible on your system. You have already demonstrated that using javap your class does not exist in the local directory, so that should be a starting point to find out where it is.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
There has nothing to do with programming here. mysql.jdbc.driver is not being loaded.I am very first to java and apache and mysql but have done everything.I have personally installed it in java main directory and the newest version.When I installed it in Tomcat.Eclipse is easily making a connection to it
Always believe in God and never let misfortunes make you give up
|
|
|
|
|
adeel1981 wrote: mysql.jdbc.driver is not being loaded.
OK, then you need to investigate why that is so. But from the information you have given here it is anyone's guess what is going wrong.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
In that case you should hope for heavenly help.
I can just tell you to use the tools that you are given.
|
|
|
|
|
I made a list of string and store data inside it ,then i made a code on this list after that i have results....my question is i want to take this results and store it in list of string . how i do that????
|
|
|
|
|
Create another list and add each result to it.
|
|
|
|
|
|
Are you trying to keep the results on same List? Because I wonder, if you have already create a List and store data, you should not stuck with creating another List and store the results in that new List. Could you please clarify, so I can help you further if required.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi to all,
public class xyz {
public static int gUserID = 1;
}
When 1st user Login gUserID value is = 5
and second user login gUserID value is = 7
Problem is 1st user refresh or re-direct to another page gUserID is changing to 7.
How to set Global variable for session or any solution to above problem.
Thanks.
|
|
|
|
|
How is the variable being updated?
The single variable is used by every instance of the class. If you want each instance to have a userId then you need something like this:
public class Test {
private static int nextUserId = 1;
private int userId;
public Test() {
this.userId = Test.nextUserId++;
}
public int getUserId() {
return this.userId;
}
}
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Hi Nagy Vilmos,
I m update gUserID from database. As soon as login to application. I m setting corresponding user id to that variable and I m utilizing that variable in complete project as global variable.
here I m facing problem. As soon as 2nd person login The Value is reset (2nd user id is updating).
I m trying your method now Thanks.
|
|
|
|
|
Now I understand.
You have an instance for each user, so the variable must not be static . If it is possible to set the value in the constructor, then that is the best thing because you can make the member variable final and so it cannot be changed.
It is strongly advised to not expose member variables outside the class, it is ALWAYS better to use in this case a method; as I used in my example. If the variable is final , then you can to some extent relax the rule as there is no way it can be changed; but this is normally reserved for constants.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
my +5.
I would like to point out that the UserID should also be an automatically created number that the user object should not modify - it's hard to identify the data otherwise.
|
|
|
|
|
Nanda_MR wrote: How to set Global variable for session
You start by researching how to handle session data in a web application.
|
|
|
|
|
Hi,
I have a problem on getting the project path of a web application.
Reason on getting the project path is I'm uploading a PDF Files to the project path so that I can open it to the browser, I'm hoping to do this http://localhost:8080/PDFviewer/UploadedFiles/sample.pdf .
I have found something in the Internet but the path is not in my project path
getServletContext().getRealPath("/");
My project path is D:\Java\Java Web Projects\PDFviewer but the above code is giving me D:\Java\Java Web Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\PDFviewer
Can anybody please suggest a way of getting the application path in java.
Thanks...
|
|
|
|
|
The path the system gives you is correct, because the web server is placed in the wtpwebapps folder.
Try to deploy it and see if the path comes up correct on a test system. I assume so.
|
|
|
|
|
Thank you very much it work perfectly what I expected...
Even if its not in my Eclipse Web Project it can view the pdf.
|
|
|
|