|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
mysql and java
Hi everyone,
im a newbie here, so im gonna introduce myself and then begin with my problem, My name is Jose, im from Venezuela. im a College student and again, im a newbie when it comes to java. anyway, i know a thing or two. i was hoping that i could find some information here about connecting to mysql databases with java, using jdbc or whatever. if any of you could help me, ill thank you for ever! hey, any kind of information for newbies will do, is a project im doing for my uncle's company. well, i've no more to say but thanks for reading and for your atention! Bye, Jose. |
|
#2
|
||||
|
||||
|
I'm having a similar problem using the JDBC driver available at URL
Try going there and install the ConnectorJ driver. I haven't got this working properly myself so if you succeed I'd be grateful if you told me about it. |
|
#3
|
|||
|
|||
|
yeah sure... but i still havent success in my problem. bye!
|
|
#4
|
|||
|
|||
|
I'm not sure whether tis will fix ur problem..
paste this executable jar file: mysql-connector-java-3.0.9-stable-bin into C:\...\Tomcat 4.1\common\lib |
|
#5
|
|||
|
|||
|
have a look at the code I have pasted
It worked for me I will try to upload the book I got it from in pdf format hope this helps you Kiwiburger package mysqltest; import java.sql.*; /** * <p>Title: MySQL Database Connection </p> * <p>Description: This was the first attempt to connect to a MySQL database</p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author Kiwiburger * @version 1.0 */ public class msql_test { Connection connection; private void displaySQLErrors(SQLException e) { System.out.println("SQLException: " + e.getMessage()); System.out.println("SQLState: " + e.getSQLState()); System.out.println("VendorError: " + e.getErrorCode()); } public void connectToDB() { try { //change the user name and password to yours String userName = "username"; String password = "password"; //change the database name to your db String url = "jdbc:mysql://localhost/databasename"; Class.forName ("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection (url, userName, password); System.out.println ("Database connection established"); }catch(SQLException e) { displaySQLErrors(e); }catch(ClassNotFoundException cnfe){ System.err.println("Unable to find and load driver: " + cnfe.getException()); System.exit(1); } } public void executeSQL() { try { Statement statement = connection.createStatement(); //change the table name to your table ResultSet rs = statement.executeQuery("select * from tablename;"); //I have multiple strings in the table I was using for the example...just //add or change as you need them while (rs.next()) { System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5) + " " + rs.getString(6) + " " + rs.getString(7) + " " + rs.getString(8) + " " + rs.getString(9) + " " + rs.getString(10) + " " + rs.getString(11) + " " + rs.getString(12) + " " + rs.getString(13) + " " + rs.getString(14) + " " + rs.getString(15)); } rs.close(); statement.close(); connection.close(); }catch(SQLException e) { displaySQLErrors(e); } } public static void main(String[] args) { msql_test mysql_test = new msql_test(); mysql_test.connectToDB(); mysql_test.executeSQL(); } } //hope this helps....it works for me //email me at paulstewart@maxnet.co.nz if it worked Last edited by kiwiburger : May 1st, 2004 at 05:44 AM. Reason: adding email address |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > mysql and java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|