java.sql导入不起作用 [英] java.sql import not working
问题描述
我的.getTables
和.prepareStatement
无法正常工作.我以为只需要导入java.sql.*
即可使它们起作用.请让我知道我还需要做什么.感谢您的时间.这两行旁边都显示找不到符号",将无法编译.
My .getTables
and .prepareStatement
are not working. I thought I only had to import the java.sql.*
for these to work. Please let me know what else I need to do. Thank you for your time. It says "cannot find symbol" next to both lines and will not compile.
import edu.lcc.citp.inventory.Product;
import java.sql.DriverManager;
import javax.jms.Connection;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import javax.jms.JMSException;
public class DatabaseProductDao implements DataAccessObject<Product> {
Connection con;
public DatabaseProductDao() throws SQLException, JMSException, ClassNotFoundException {
Class.forName("cockeb.org.apache.derby.jdbc.ClientDriver");
try (Connection con = (Connection) DriverManager.getConnection("jdbc:derby://localhost:1527/store;create=true")) {
boolean exists = con.getMetaData().getTables(null, null, "PRODUCT", null).next();
if (exists) {
System.out.println("Table Exists");
} else {
String createDml = "CREATE TABLE PRODUCT (UPC VARCHAR(25), SHORT_DETAILS VARCHAR(50), LONG_DETAILS VARCHAR(5000), PRICE DECIMAL(10,2), STOCK INTEGER, PRIMARY KEY (UPC))";
PreparedStatement createStatement = con.prepareStatement(createDml);
createStatement.execute();
}
} catch (SQLException e) {
System.out.println("Can Not Connect At This Time");
}
}
推荐答案
问题与导入有关.
您导入了javax.jms.Connection
,这是绝对错误的.只需删除它即可.
您想要的是java.sql(java.sql.Connection
)包中的Connection类.
The problem is with imports.
You imported javax.jms.Connection
which is obiously wrong. Just delete it.
What you wanted is Connection class from java.sql (java.sql.Connection
) package.
我也不建议在导入中使用通配符(.*
),而是选择您实际使用的特定类.对于您的情况:
Also I do not suggest to use wildcards (.*
) in import but pick specific class you actually use. In your case:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
这篇关于java.sql导入不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!