|
|
|
|
![]() ![]() |
Nov 28 2007, 11:47 PM
Post
#1
|
|
|
Sparkx Group: [HOSTED] Posts: 354 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 |
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 m ysql. I think it has something to do with JDBC but I might be wrong. Thanks for all the help, Sparkx This post has been edited by sparkx: Nov 28 2007, 11:49 PM |
|
|
|
Nov 29 2007, 05:51 AM
Post
#2
|
|
|
Advanced Member Group: Members Posts: 170 Joined: 30-July 07 Member No.: 23,704 |
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:
CODE 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. CODE import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; Cheers |
|
|
|
Dec 3 2007, 11:01 PM
Post
#3
|
|
|
Sparkx Group: [HOSTED] Posts: 354 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 |
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 astahost) 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, Sparkx Note: 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. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 11th October 2008 - 06:20 PM |