gpt4 book ai didi

java - 如何修复此 "package does not exist"错误?

转载 作者:行者123 更新时间:2023-12-02 00:49:06 26 4
gpt4 key购买 nike

在 OS X 上。

$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)

这是我的整个项目:

$ ll
total 1072
-rw-r--r-- 1 ethan ethan 1316 Oct 19 17:17 BlackberryDataExtractor.class
-rw-r--r-- 1 ethan ethan 1439 Oct 19 18:05 BlackberryDataExtractor.java
-rw-r--r--@ 1 ethan ethan 537303 Apr 19 2010 sqljdbc4.jar
<-- MS SQL Server JDBC driver

这是 BlackberryDataExtractor.java。它还没有真正做任何事情。我只是想让基本的东西像数据库连接一样工作:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.microsoft.sqlserver.jdbc;

class BlackberryDataExtractor {

public static void main(String[] args) {
Connection con = BlackberryDataExtractor.getConnection();
}

public static final Connection getConnection()
{
Connection con = null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://[ etc... ]");
String SQL = "SELECT uc.MailboxSMTPAddr AS email, sd.PhoneNumber AS phone_number"
+ "FROM dbo.UserConfig uc, dbo.SyncDeviceMgmtSummary sd"
+ "WHERE sd.UserConfigId = uc.Id";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(SQL);

while (rs.next()) {
System.out.println(rs.getString("email") + ", " + rs.getString("phone_number"));
}
rs.close();
stmt.close();

}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
return con;
}
}

它不会编译。错误如下:

$ javac -cp "$CLASSPATH;*.jar" BlackberryDataExtractor.java
BlackberryDataExtractor.java:4: package com.microsoft.sqlserver does not exist
import com.microsoft.sqlserver.jdbc;
^
BlackberryDataExtractor.java:23: cannot find symbol
symbol : class Statement
location: class BlackberryDataExtractor
Statement stmt = con.createStatement();
^
BlackberryDataExtractor.java:24: cannot find symbol
symbol : class ResultSet
location: class BlackberryDataExtractor
ResultSet rs = stmt.executeQuery(SQL);
^
3 errors

最佳答案

javac 无法识别 *.jar 等通配符。你必须明确。

尝试 javac -cp "$CLASSPATH;sqljdbc4.jar"...

关于java - 如何修复此 "package does not exist"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3974114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com