链接数据库时 出现这样的警告:Errors exist in required project
2011-08-24 08:01
441 查看
今天我尝试了链接了数据:
/**
* @(#)JDBC.java
*
*
* @author
* @version 1.00 2011/8/24
*/
import java.sql.*;
public class JDBC {
public static void main(String[] args) {
// 声明JDBC驱动程序类型
String JDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//定义JDBC驱动程序对象
String conURL = "jdbc:sqlserver://localhost;databaseName=mayi;user=sa;password=123";
Connection con = null;
PreparedStatement ps = null;
// Statement s=null;
ResultSet rs = null;
try {
///加载驱动
Class.forName(JDriver);
///链接数据库URL
con = DriverManager.getConnection(conURL);
///数据库操作
ps = con.prepareStatement("select * from users");
rs = ps.executeQuery();
while (rs.next()) {
System.out.println(" userId:" + rs.getInt(1) + " username:"
+ rs.getString(2) + " userPassword:" + rs.getString(3)
+ " email:" + rs.getString(4) + " grade:"
+ rs.getInt(5)+"\n");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
///关闭链接
try {
if(rs!=null){
rs.close();
rs=null;
}
if (ps != null) {
ps.close();
ps = null;
}
if (con != null) {
con.close();
con = null;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
编译运行,出现了这样的错误:Errors exist in required project 运行可以得到正确的数据!!
网上搜一下: 原因如下:
因为可能是同一个工程中的其他代码有错误,而执行的代码与这个有错误的代码没有关系,因为在同一个project,Eclipse依然会报错,但没有影响到执行的那段代码
/**
* @(#)JDBC.java
*
*
* @author
* @version 1.00 2011/8/24
*/
import java.sql.*;
public class JDBC {
public static void main(String[] args) {
// 声明JDBC驱动程序类型
String JDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//定义JDBC驱动程序对象
String conURL = "jdbc:sqlserver://localhost;databaseName=mayi;user=sa;password=123";
Connection con = null;
PreparedStatement ps = null;
// Statement s=null;
ResultSet rs = null;
try {
///加载驱动
Class.forName(JDriver);
///链接数据库URL
con = DriverManager.getConnection(conURL);
///数据库操作
ps = con.prepareStatement("select * from users");
rs = ps.executeQuery();
while (rs.next()) {
System.out.println(" userId:" + rs.getInt(1) + " username:"
+ rs.getString(2) + " userPassword:" + rs.getString(3)
+ " email:" + rs.getString(4) + " grade:"
+ rs.getInt(5)+"\n");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
///关闭链接
try {
if(rs!=null){
rs.close();
rs=null;
}
if (ps != null) {
ps.close();
ps = null;
}
if (con != null) {
con.close();
con = null;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
编译运行,出现了这样的错误:Errors exist in required project 运行可以得到正确的数据!!
网上搜一下: 原因如下:
因为可能是同一个工程中的其他代码有错误,而执行的代码与这个有错误的代码没有关系,因为在同一个project,Eclipse依然会报错,但没有影响到执行的那段代码
相关文章推荐
- eclpse运行项目出现errors exist in required project(s)
- jd-gui反编译全过程,myeclipse中java web项目jar包没有红叉仍然显示感叹号,运行main函数提示errors exist in required project(s)
- eclipse import工程出现Some projects cannot be imported because they already exist in the workspace
- 导入项目后 出现Unbound classpath container: 'JRE System Library [jdk1.6.0_04]' in project '项目名'这样的错误
- 数据库中 关于不能用in 不能用exist 等关键字 查询不出现字段的问题
- SqlServer2005 恢复数据库时出现Exclusive access could not be obtained because the database is in use 的解决方法
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- 解决Eclipse导入项目是提示错误:Some projects cannot be imported because they already exist in the workspace
- SQL优化- 数据库SQL优化——使用EXIST代替IN
- Android Studio 出现Frameworks detected:Android framework is detected in the project Configure
- Some Errors Usually Seen In Android Project
- Android ndk 编译出现'Build Project' has encountered a problem.Errors occurred during the build
- 安装 MySQLdb 出现 Python version 2.7 required, which was not found in the registry
- Serv_U 安全设置以后出现530 Not logged in, home directory does not exist的解决方法
- SqlServer2005 恢复数据库时出现Exclusive access could not be obtained because the database is in use 的解决方法
- MyEclipse 中添加工程显示Some projects cannot be imported because they already exist in the workspace
- Archive for required library: "xxxx" in project '*' cannot be read or is not a valid ZIP file
- 安装第三方库出现 Python version 2.7 required, which was not found in the registry
- Some projects cannot be imported because they already exist in the workspace
- 解决Eclipse导入项目是提示错误:Some projects cannot be imported because they already exist in the workspace