大哥们来看看eclipse的问题
我写的一段连接mysql的代码。。。直接用javac和java可以运行,并且正确
但是当我在eclipse下编译的时候,就出现如下的错误:
java.lang.Error: Unresolved compilation problem:
at test.FirstSample.main(FirstSample.java:1)
Exception in thread "main"
请问这个是怎么回事啊???
问题点数:20、回复次数:8Top
1 楼jimmyvk(J仔)回复于 2005-05-09 17:53:18 得分 5
把代码拿出来看看啊Top
2 楼zhrenxi(柯希)回复于 2005-05-09 23:29:48 得分 0
/**
* Created on 2005-5-7
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author 张人希
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.sql.*;
public class FirstSample
{
public static void main(String[] args)
{
// The JDBC URL format for MySQL Connector/J is as follows, with items
// in square brackets ([, ]) being optional:
// jdbc:mysql://[host][,failoverhost...][:port]/[database][?propertyName1]
// [=propertyValue1][&propertyName2][=propertyValue2]...
// If the hostname is not specified, it defaults to '127.0.0.1'.
// If the port is not specified, it defaults to '3306',
// the default port number for MySQL servers.
String url = "jdbc:mysql://localhost:3306/wszp?user=root&password=zrx";
// System.out.println("Show something...");
try
{
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// Connection conn = DriverManager.getConnection(url);
// Statement stat = conn.createStatement();
//
// ResultSet result = stat.executeQuery("show tables();");
//
// System.out.println(result.getString(1));
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
// stmt.execute("create table greetingf (id char(20));");
//stmt.execute("insert into greetingf values ('123,456!');");
//System.out.println("Show something...");
ResultSet result = stmt.executeQuery("select * from wszp_Company;");
result.next();
System.out.println(result.getString(1));
System.out.println(result.getString(2));
result.close();
stmt.close();
con.close();
}
catch (Exception ex)
{
// handle the error
System.out.println(ex.getMessage());
}
}
}
Top
3 楼zhrenxi(柯希)回复于 2005-05-10 22:29:35 得分 0
自己upTop
4 楼keelsike(blog.k99k.com)回复于 2005-05-11 08:29:23 得分 10
项目中加入MYSQL的驱动包没?Top
5 楼wenchaohu213(夏吾)回复于 2005-05-11 08:54:48 得分 0
怎么连你JDBC的驱动都没有办法实现
数据库连不上的Top
6 楼zhrenxi(柯希)回复于 2005-05-11 17:54:33 得分 0
现在问题是这样的:我是建立Lomboz J2EE Project。我期间选择了创建Web modules...并且添加的外部包。。
然后我在新建立的Web modules中添加一个class,即上面所写的程序代码,就出现如上的错误
但是如果我不是在web modules下创建,而是在正个项目下创建就不会出现这样的问题。
而现在的问题,我在原有的项目下创建一个文件夹,文件夹下面的class也不能正确运行连接MySQL,但是其他的java代码(非数据库连接)可以正常运行```请问这样的问题怎么解决?????Top
7 楼zhrenxi(柯希)回复于 2005-05-13 12:00:48 得分 0
upTop
8 楼ayace(红日)(低调的路过)回复于 2005-05-15 01:38:28 得分 5
新建的Web项目中有mysql的驱动吗?Top




