import java.sql,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 {

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");

}

}

解决方案

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值