| | |
Connecting to a mysql database
Thread Solved |
Ok so what i want to be able to do is connect to a mysql database. Here's my code so far:
The problem is though that it keeps saying it could not find the database driver, even though i put postgresql-8.4-701.jdbc4.jar in the project file. So therefore it should find it, or is this not the driver? Im using java 1.6, snow leopard os and eclipse. By the way, the password isnt test but im not going to tell you it
Thanks,
jakx12.
Java Syntax (Toggle Plain Text)
Connection connection = null; try { // Load the JDBC driver String driverName = "postgresql-8.4-701.jdbc4.jar"; // MySQL MM JDBC driver Class.forName(driverName); // Create a connection to the database String serverName = "mysql10.000webhost.com"; String mydatabase = "a2362883_test"; String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url String username = "a2362883_admin"; String password = "test"; connection = (Connection) DriverManager.getConnection(url, username, password); System.out.println("Connected"); } catch (ClassNotFoundException e) { System.out.println("Could not find the database driver"); } catch (SQLException e) { System.out.println("Could not connect to the database"); }
The problem is though that it keeps saying it could not find the database driver, even though i put postgresql-8.4-701.jdbc4.jar in the project file. So therefore it should find it, or is this not the driver? Im using java 1.6, snow leopard os and eclipse. By the way, the password isnt test but im not going to tell you it

Thanks,
jakx12.
Last edited by jakx12; 21 Days Ago at 2:15 pm.
There are 10 types of people in this world, those that understand binary and those that don't :).
0
#2 21 Days Ago
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
0
#5 21 Days Ago
The MySQL documentation shows you which class, at the very beginning of the page I linked to, and the tutorials (and the MySQL docs) show you how to use it. Read those.
Edit: Besides, why would you be loading a postgresql Driver (jar) when it is mysql (according to your title) that you want to connect to?
Edit: Besides, why would you be loading a postgresql Driver (jar) when it is mysql (according to your title) that you want to connect to?
Last edited by masijade; 21 Days Ago at 6:58 pm.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Connecting to MySQL database- Run-time error 3001 (Visual Basic 4 / 5 / 6)
- Need Help in Connecting MySQL Database to JTable (Java)
- Problem while connecting MySQL database through ODBC (C#)
- Problems connecting jsp with MySQL database (JSP)
- Connecting VB6 to a MySQL Database across the internet (Visual Basic 4 / 5 / 6)
- Connecting A Website To a DataBase (MySQL)
- MSSQL - MySql Database Connectivity (MS SQL)
- can i use mysql database with asp (ASP)
- connecting java to mysql database (Java)
- copying mssql database on my local machine to a mysql database online (MySQL)
Other Threads in the Java Forum
- Previous Thread: HELP with code
- Next Thread: Java ActionListener Question
| Thread Tools | Search this Thread |
actuate add android api applet application applications array arrays automation balls bank binary bluetooth business chat class clear client code codesnippet collections component database defaultmethod development dice digit dragging ebook eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health hql html hyper ide idea image infinite int integer invokingapacheantprogrammatically j2me java javame javaprojects jni jpanel julia linux list main map method methods mobile myregfun mysql netbeans nonstatic openjavafx parameter pearl php problem program project recursion repositories scanner scrollbar server set sms sort sorting spamblocker sql sqlserver state storm string sun superclass swing swt thread threads tree windows






