小编Cod*_*ino的帖子

java h2内存数据库错误:找不到表

我试过谷歌搜索,但几乎所有这类问题的解决方案是添加;DB_CLOSE_DELAY=-1,但它并没有为我解决任何问题.

这是我的测试课

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {Main.class})
public class Testas {

    @Autowired
    @Qualifier("managerImplementation")
    private ClassifierManager manager;

    @Test
    public void testManager(){
        ClassifierGroupEntity cge = new ClassifierGroupEntity();
        manager.saveClassifierGroup(cge);
    }
}
Run Code Online (Sandbox Code Playgroud)

经理班

@Service("managerImplementation")
public class ClassifierManagerImpl implements ClassifierManager{

    @Autowired
    private ClassifierGroupEntityRepository groupEntityRepository;

    @Autowired
    private ClassifierEntityRepository entityRepository;

    @Autowired 
    private ClassifierValueEntityRepository valueEntityRepository;

    @Override
    public ClassifierGroupEntity getClassifierGroup(long id) {
        return groupEntityRepository.findOne(id);
    }

    @Override
    public ClassifierGroupEntity getClassifierGroup(String code) {
        return groupEntityRepository.findByCode(code);
    }

    @Override
    public ClassifierGroupEntity saveClassifierGroup(ClassifierGroupEntity entity) {
        return groupEntityRepository.save(entity);
    }

    @Override
    public void deleteClassifierGroup(long id) …
Run Code Online (Sandbox Code Playgroud)

java spring jdbc h2

7
推荐指数
3
解决办法
2万
查看次数

从arraylist中提取子类的所有实例

我有ArrayList<Unit> units.我想编写一个函数,它将返回指定子类的所有对象,用作参数.但是我无法让它发挥作用.这是我有的:

public static ArrayList<? extends Unit> getTheseUnits(Class<? extends Unit> specific_unit) {
    ArrayList<specific_unit> res = new ArrayList<>();  //'specific_unit' is in red here. Adding '.class' or '.getClass()' after it does not resolve anything
    for (Unit u : units){
        if (u instanceof specific_unit){
            res.add(u);
        }
    }
    return res;
}
Run Code Online (Sandbox Code Playgroud)

java generics arraylist

5
推荐指数
1
解决办法
621
查看次数

用于生成不重复的,间隔开的RGB颜色值的算法

我想要一个静态方法,每当被调用时,它将返回一个尚未出现的颜色值,并且不会太接近上一次返回的颜色(即return new Color(last_value += 10)不会这样做).它也应该是随机的,因此每次启动应用程序时,返回的颜色序列都是相同的.

突然出现的第一件事就是迭代一个带有原始数字步骤的数组,如下所示:

    private static HashMap<Integer, Boolean> used = new HashMap<>();
    private static int[] values = new int[0xfffff]; // 1/16th of possible colors
    private static int current = 0, jump = values.length / 7;

     public static Color getColour(){
        int value = values[current];
        used.put(current, true);
        current += jump;
        current %= values.length;
        //have some check here if all colors were used
        while (used.containsKey(current)){
            current++;
            current%=values.length;
        }
        return new Color(value);
    }
Run Code Online (Sandbox Code Playgroud)

但是我不喜欢它,因为从某些回调中颜色会彼此接近.

java algorithm colors

5
推荐指数
1
解决办法
153
查看次数

Java Spring 返回使用 BOM 编码的 UTF-8 CSV 文件

显然,要让 excel 很好地打开 CSV 文件,它的开头应该有字节顺序标记。CSV 的下载是通过写入HttpServletResponse控制器中的输出流来实现的,因为数据是在请求期间生成的。当我尝试写入 BOM 字节时出现异常 - java.io.CharConversionException: Not an ISO 8859-1 character: [](即使我指定的编码是UTF-8)。


控制器的方法有问题

@RequestMapping("/monthly/list")
public List<MonthlyDetailsItem> queryDetailsItems(
        MonthlyDetailsItemQuery query,
        @RequestParam(value = "format", required = false) String format,
        @RequestParam(value = "attachment", required = false, defaultValue="false") Boolean attachment,
        HttpServletResponse response) throws Exception 
{   
    // load item list
    List<MonthlyDetailsItem> list = detailsSvc.queryMonthlyDetailsForList(query);
    // adjust format
    format = format != null ? format.toLowerCase() : "json";
    if (!Arrays.asList("json", "csv").contains(format)) format = "json";

    // modify common response …
Run Code Online (Sandbox Code Playgroud)

java spring byte-order-mark utf-8

5
推荐指数
1
解决办法
7923
查看次数

从 Java 调用带有表类型参数的 OracleDB 过程 — DB 始终接收空值而不是值

由于某种原因,数据库没有收到通过表参数给出的值。它看到表中的行数是正确的,并且给定的列数也是正确的(否则我会收到不匹配的错误),但值本身为空。

数据库版本 ( SELECT * FROM V$VERSION):

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
PL/SQL Release 12.1.0.2.0 - Production
"CORE   12.1.0.2.0  Production"
TNS for 64-bit Windows: Version 12.1.0.2.0 - Production
NLSRTL Version 12.1.0.2.0 - Production
Run Code Online (Sandbox Code Playgroud)

使用 Oracle 驱动程序 ojdbc6(版本 11.2.0.4)、ojdbc7(版本 11.2.0.4)、ojdbc7(版本 12.1.0.2)进行测试。

这是数据库过程的签名:

Procedure Send_Message_Test (
    i_Receiver_List_Users_Tbl    In Receiver_List_Users_Tbl
);
Run Code Online (Sandbox Code Playgroud)

类型:

CREATE OR REPLACE Type Receiver_List_Users_Rt Force As Object (
  User_Id Varchar2(30 Char)
)
/

CREATE OR REPLACE Type Receiver_List_Users_Tbl Is Table Of Receiver_List_Users_Rt
Run Code Online (Sandbox Code Playgroud)

这是调用它的最小完整 Java …

java oracle plsql spring-boot

5
推荐指数
1
解决办法
2222
查看次数

Java声音生成会产生噪音

我正在使用javax.sound来制作声音,但是当你演奏时它们会在背景中产生某种噪音,如果你一次演奏几个音符,它甚至可以克服声音.这是代码:

public final static double notes[] = new double[] {130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185,
        196, 207.65, 220, 233.08, 246.94, 261.63, 277.18, 293.66,
        311.13, 329.63, 349.23, 369.99, 392, 415.3, 440, 466.16,
        493.88, 523.25, 554.37};



public static void playSound(int note, int type) throws LineUnavailableException {          //type 0 = sin, type 1 = square

    Thread t = new Thread() {
        public void run() {
            try {

                int sound = (int) (notes[note] * 100);


                byte[] buf = new byte[1];
                AudioFormat af = …
Run Code Online (Sandbox Code Playgroud)

java midi

3
推荐指数
1
解决办法
499
查看次数

HTTP 中的标头接受

我在 http 中遇到“Accept”标头的问题。我写了一个http客户端,当我设置“接受:image/png”时,我仍然可以读取任何文件(如txt、html等)。我认为当像上面那样设置标题“Accept”时,这是不可能的。

我尝试检查我的 Firefox 的行为方式。我写了“about:config”并将“network.http.accept.default”设置为“image/png”,我就可以像平常一样上网了。

我是否误解了这个标题的含义?我认为我应该只能打开文件 *.png。

network-programming protocols http http-headers

2
推荐指数
1
解决办法
2838
查看次数