Jump to content
xisto Community
Sign in to follow this  
sparkx

Java Db Help Pls

Recommended Posts

Now I am a compleate newbie to java. Now just from saying that I will get posts that say "read the basics first" ect. I know the basics but the way I learn isn't just by going over basics. What I want to do/know is if it is possible to connect to a MySQL Database using java. Is it possible and if so how? Tutorials and links to tutorials are welcome along with maby a list of required packages and an example code of connecting/selecting data. This is for MySQL not SQL (I don't know if there is a major difference in java or not). I am currently using SDK1.4.2_16. I have various other packages installed already. I know the basics about java (in 3D at least) but I am compleatly clueless on Java connection to mysql. I think it has something to do with JDBC but I might be wrong.Thanks for all the help,Sparkx

Edited by sparkx (see edit history)

Share this post


Link to post
Share on other sites

Basically, making Java application connecting to mySQL and any other database eg. ORACLE, its the same. The only different is the connection string. For mySQL, I've used:

Connection con = null;Class.forName("com.mysql.jdbc.Driver").newInstance();con = DriverManager.getConnection("jdbc:mysql:///test","root", "secret");

After that, use the con variable to execute all the SQL queries. For how to execute the queries, you can do a google search and you should get a lot of information.

Anyway before all the connection to mySQL database, you should import all the classes and installed all mySQL services. Hope this help.

import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;

Cheers

Share this post


Link to post
Share on other sites

Thansk. I have been having trouble with this still. I get some errors like App notinted or something along those lines. Could anyone post the entire code for connecting and displaying entries. Just say I have a mysql database (on Xisto) called testdb (I guess the name doesn't matter I could alway change it). Then display all the entries for Name that are in testdb. I learn best by jumping right into the code so you don't neccissarly need to explain it (although that would help) but what I am looking for is a complete source (unless that is to long). I have worked with mysql lots in php but for some reason when I upload my java files I can't get them to work.Thank you very much,SparkxNote: I am not exactly sure if the error I am getting is related to the script at all it may be something with my compiler. I have gotten the error on other project also that don't connect to databases, however my compiler works on simple projects still.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.