简体   繁体   中英

Eclipse - How can I open a sql file?

I am a beginner in Java Programming and on Eclipse. I have recently downloaded a java project on the internet, and when I try to execute it, it works at the beginning, but when I try to add a item in the data base the following error is displayed in the console:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
java.lang.NullPointerException

I've downloaded :

Data Tools Platform SQL Development Tools org.eclipse.datatools.sqldevtools.feature.feature.group

And I've also added my sql files by doing these instructions:

New -> Others -> SQL Developpement -> SQL File -> Paste ( the downloaded sql code)

Please can someone help me ?

If you'd like to stick with Eclipse, I've found HSQLDB to work well with it. It's a free, very quick download.This would, however, replace MySQL in the project you downloaded and probably wouldn't be a good first go.

However, if you'd instead like to start from scratch with tutorials on the basics, then work your way up to SQL I suggest HSQLDB. http://hsqldb.org/

To include HSQLDB in your first project within Eclipse, right click your project in the project list within Eclipse > Build Path... > Libraries tab > Add External JARs... then select the HSSQL jar file you downloaded.

Again, this is if you're going to start from scratch in building your first program. I'm suggesting this because it's precisely the path I went down to get my feet wet with Java, Eclipse, and database handling.

You didn't mention how you've already tried to solve this one. When you encounter some type of Exception, always look up what it means. They don't tend to be thrown at random.

In this case, you don't seem to have the MySQL driver on the project's Java Build Path . You might want to spend some time familiarizing yourself with the concepts you'll be working with, but at minimum, you need the MySQL driver jar to be in the project. Once you have that, right-click on it from inside of the Package Explorer View and add it to the Java Build Path .

There are also some very good tutorials you can look at. Developing software is never intuitive. Don't give up.

The short answer is that "com.mysql.jdbc.Driver" is not in your classpath. This means you need to install mysql support libraries. Making sure Eclipse (actually the java plugin) is configured properly can be a bit of a nightmare.

If you are very new to java development, it may be better to start with Netbeans, JDeveloper, or IntelliJ. These tend to "just work" compared to Eclipse. I think IntelliJ is the most intuitive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM