| | |
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; 24 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 24 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 24 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; 24 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 |
2dgraphics account android api apple applet application arguments array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class client code color component count database derby design eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui homework html ide if_statement image integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list macintosh map method methods midlethttpconnection mobile netbeans newbie nullpointerexception object open-source os problem producer program programming project projectideas property read recursion reference replaysolutions ria scanner search server set size sms sort sourcelabs splash sql sqlite stop string swing testautomation threads transforms tree ui unicode validation windows






