Results 1 to 12 of 12
- 07-15-2008, 09:46 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 29
- Rep Power
- 0
Connector J with Eclipse and MySQL 5.0.x
I'm trying to get MySQL and Eclipse with connector j to work. I've installed MySQL 5.0.x and it's all working well, but I don't know where to put the connector-J.xxx.jar file so I can start using it all. I've followed a few tutorials and set the jar file in the CLASSPATH etc. (set CLASSPATH=<PATH TO CJ>) and copied a copy of CJ into c:\<PATH to Java install>\lib\ext so it can be seen by the JVM. But I'm not sure if I need to do something special for/with eclipse.
I'm using win32 XP.
This is a test program to see if it's all working.....and, it's not:Java Code:public class Simi { /** * @param args */ public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); System.out.println("Good to go!"); } catch (Exception E) { System.out.println("JDBC Driver Error!"); } } }
"JDBC Driver Error!".
I'm not sure what to do next. Thanks in advance.Last edited by int80; 07-15-2008 at 10:04 PM.
- 07-16-2008, 03:37 PM #2
Member
- Join Date
- Jul 2008
- Posts
- 31
- Rep Power
- 0
It needs to be in the ext directory of the jvm that the project is set to use.
If you have JDK installed it needs to go to [JDKDIR]/jre/lib/ext.
The other option is to add the mysql jar to your project libraries.
HTH
Stephen
- 07-16-2008, 04:00 PM #3
Member
- Join Date
- Jul 2008
- Posts
- 29
- Rep Power
- 0
- 07-16-2008, 04:42 PM #4
Member
- Join Date
- Jul 2008
- Posts
- 31
- Rep Power
- 0
You still need that,
Heres a generic class which is more or less what I use
Note that i am returning a java.sql.Connection and not a com.mysql.jdbc.Connection, this helps if you ever need to change the Database provider.Java Code:import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class MysqlConnectionProvider { private static MysqlConnectionProvider INST; private MysqlConnectionProvider() throws ClassNotFoundException { Class.forName("com.mysql.jdbc.Driver"); } public static Connection getNewConnection(String host, String database, String user, String password) throws SQLException, ClassNotFoundException { if (INST == null) { INST = new MysqlConnectionProvider(); } return INST.createConnection(host, database, user, password); } public Connection createConnection(String host, String database, String user, String password) throws SQLException { String url = new String("jdbc:mysql://" + host + "/" + database); return DriverManager.getConnection(url, user, password); } }
Also remember to close preparedstatements and resultsets after use to prevent memory leaks.
eg
StephenJava Code:java.sql.PreparedStatement ps = null; java.sql.ResultSet rs = null; try{ ps = connection.prepare...... rs = ps.executeQuery(); //work with rs here } catch (SQLException s){ //handle error here } finally{ if (rs != null) { try { rs.close(); } catch (SQLException e) { } } if (ps != null) { try { ps.close(); } catch (SQLException e) { } } }
- 07-16-2008, 06:01 PM #5
Member
- Join Date
- Jul 2008
- Posts
- 29
- Rep Power
- 0
Thanks alot! Will take a look at that. :D
- 09-08-2008, 01:13 AM #6
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Eclipse 3.4 Ganymede & MySQL
My PC runs Windows Vista. I installed Eclipse 3.4 Ganymede and would like to work with MySQL through the Eclipse. I already have the MySQL 5.1 installed. For working with it in the Eclipse, I have downloaded the MySQL Connector/J 5.1.6 and, by the installation docs, have to set the CLASSPATH environment variable. However, I don't see how to do that.
On the other hand, I opened the "Database Development" perspective in the Eclipse, and tryed to create Connection through the "Data Source Explorer", following the wizard leading through the process. Unfortunately, I failed to get the correct result. Only I had "Ping failed" or "Couldn't connect to NewMySQL"
- 09-08-2008, 10:05 AM #7
Member
- Join Date
- Jul 2008
- Posts
- 29
- Rep Power
- 0
I didn't do any of that in the end. I just right clicked on the folder containing the package and classes, went to properties, goto Java Build Path, Add external Jars, and then added the j connector jar file. Before you do that, put j connector jar in the workspace file.
I hope that helps.
- 09-09-2008, 01:46 AM #8
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Eclipse 3.4 Ganymede & MySQL
Thanks alot, int80.
I found the solution (with your help!)
The key issue was to put the downloaded directory "mysql-connector-java-5.1.6" which contains the "mysql-connector-java-5.1.6-bin.jar" into the directory "eclipse", and to rename the driver in eclipse. After that, the "Database Development" perspective got working as needed
- 09-09-2008, 08:52 AM #9
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Loading text into MySQL table
Hi,
I have a text file to use it as INFILE for SQL command LOAD into a table. The table has fields of the type DATE. Some strings representing dates in the text are actuall NULLs and contain only "/ /". How can I nicely load this text into the table?
P.S. The text originates from the DBF-file, as exported through FoxPro. I found only the "text delimited by ..." export option in FoxPro is in accordance with the MySQL options to import tables from the foreign formats.
Thanks in advance
- 10-31-2008, 09:37 PM #10
Member
- Join Date
- Oct 2008
- Posts
- 2
- Rep Power
- 0
Hi Kesler,
Could you please show how to rename the driver in eclipse. Also, do I need to copy the entire directory in to the Eclipse directory ?.
Thanks
Raj Kairam
- 11-01-2008, 12:38 AM #11
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Hi, kairamr
Unfortunately, I haven't found the DB project where I made the described in my post. So, I'll answer you relying on my memory.
The naming of the driver in Eclipse doesn't matter. My problem was that at the start of the project, when I tryed connection to mySQL, I used the Eclipse defaults about the driver, and Eclipse was not able to find the driver, because it was not in the right place. My attempt to use different drivers, places, etc. with the initial (default) driver name were unsuccessful until I changed the name having relocated the connector/driver in the native Eclipse directory (I mean "plugins"), Eclipse "swallowed" that up and start working. Later I found out Eclipse now has two driver. The initial one doesn't work, and the new one do works, despite of the name I have chosen for it. I didn't think much about the name. Sincerely hoping this will help you.
- 05-31-2010, 09:32 AM #12
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
eclipse and xampp/mysql connector/j
Hi all,
It took ages but I finally found the cause of my problem with eclipse on a win xp environment. After you D/L the mysql connector/j for java. Open your project in eclipse and go into project/properties. Select "Java build Path" and click on Libraries. You'll see a button called "Add External Jar's". Click on it to open a browsing dialog and navigate to the directory that you've extracted mysql connector/j into and select "mysql-connector-java-5.1.12-bin.jar" file.(That's the one I have anyway) and click "ok". It should be added to your project.
The next step is the code:
Mine is:
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
public class jdbc
{
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Good to go");
}
catch (Exception ex)
{
System.err.println("Got an exception! ");
System.err.println(ex.getMessage());
}
}
}
The above code is from another forum by whoever(thank's whoever you are), not class path, no environment variables, clean and simple.
Regards
Similar Threads
-
MySQL connector selection
By Ms.Ranjan in forum JDBCReplies: 3Last Post: 06-23-2008, 05:27 PM -
fetching document content and MIME_TYPE through share-point connector API
By suresh72 in forum Advanced JavaReplies: 0Last Post: 12-19-2007, 11:47 AM -
Mysql Help
By Sumendra Maharjan in forum JDBCReplies: 1Last Post: 08-08-2007, 01:19 AM -
JCA connector
By bbq in forum JDBCReplies: 1Last Post: 07-05-2007, 04:31 AM -
JSP and MySQL
By Ed in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 07-04-2007, 05:08 AM


LinkBack URL
About LinkBacks


Bookmarks