小编Mar*_*eel的帖子

获取java.sql.SQLException: - ORA-01000:DML超出最大打开游标数(更新语句)

我正在读取包含30000行的excel文件,并尝试根据某些逻辑更新Oracle dB表字段.我的Java应用程序错误输出"java.sql.SQLException: - ORA-01000:超出最大打开游标数",当它在表中写入大约700条记录时.需要帮助优化代码以避免此错误.

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.ResourceBundle;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import oracle.jdbc.driver.OracleDriver;

public class UpdateTest {
    private static Connection conn = null;
    static ResourceBundle bundle = ResourceBundle.getBundle("PropertiesFile");
    public static void main(String[] args) {

    String filename = bundle.getString("FILEPATH") + bundle.getString("FILENAME");
    FileInputStream fileInputStream = null;
    String input = null;
    PreparedStatement preparedStatement = null;
    Integer result = null;
    int counter = 0;

    try {
        DriverManager.registerDriver(new OracleDriver());
        conn = DriverManager.getConnection( …
Run Code Online (Sandbox Code Playgroud)

java oracle jdbc

0
推荐指数
1
解决办法
393
查看次数

自我在构造函数中为对象分配对象

假设我们有:

课程Item:

public class Item {
    private Type type;

    Item(Type type) {
        this.type = type;

        if (type == Type.PISTOL || type == Type.AR || type == Type.SNIPER_RIFLE) {
            this = new Weapon(type);
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

和类Weapon继承自Item:

public class Weapon extends Item {

    Bullet.Type bulletType;
    int fireRate;

    public Weapon(Type type) {
        this.type = type;
    }
}
Run Code Online (Sandbox Code Playgroud)

它从某个地方调用,如:

Item item = new Item(Item.Type.PISTOL);
Run Code Online (Sandbox Code Playgroud)

我实际上知道this在Java中不可分配,但我想知道如何解决这种情况.

如果它的类型合适,我想分配item新的Weapon.

java inheritance constructor variable-assignment

0
推荐指数
1
解决办法
66
查看次数

在JDBC中使用isWrapperFor和unwrap函数的正确方法是什么?

我想知道isWrapperFor在JDBC中验证和解包函数的正确方法.这里HIRAConnection使用标准Connection类.

HIRAConnection hiraCon1 = (HIRAConnection) ds.getConnection();
Connection conn = ds.getConnection();
if (hiraCon1 instanceof Wrapper) {
    // try to use java 6 unwrapping
    try {
        Wrapper w = conn;
        if (hiraCon1.isWrapperFor(Connection.class)) {
            hiraCon1 = conn.unwrap(HIRAConnection.class); 
            hiraCon1= hiraCon1.unwrap(HIRAConnection.class);
            hiraCon1= ds.unwrap(HIRAConnection.class);//returns SQLException   
        }
        if (hiraCon1.isWrapperFor(HIRAConnection.class)) {
            hiraCon1 = conn.unwrap(HIRAConnection.class);
            hiraCon1 = hiraCon1.unwrap(HIRAConnection.class);    
        }
        if (conn.isWrapperFor(com.hira.HIRAConnection.class)) {          
            hiraCon1 = conn.unwrap(com.hira.HIRAConnection.class);
        } 
        if (conn.isWrapperFor(Connection.class)) {          
            hiraCon1 = conn.unwrap(com.hira.HIRAConnection.class);
        } 
    } catch (Throwable t) {
        System.out.println("Failed to unwrap connection using …
Run Code Online (Sandbox Code Playgroud)

java jdbc

0
推荐指数
1
解决办法
986
查看次数

如何获得 Composer 已知的 PHP 扩展名称?

我需要设置一个具有服务器要求的composer.json(例如php >= 5.6、lib-xml等)。Composer 文档中有一些示例,但我需要的是一种为给定 PHP 扩展或库(例如 php7.1-curl - Ubuntu 软件包名称)获取 Composer 别名(ext-xxx、lib-yyy 等)的方法。

php reference configuration-files composer-php

0
推荐指数
1
解决办法
828
查看次数

我在Java项目上找不到SqlServerDriver

我正在尝试连接到SQL Server并将数据插入数据库中。我有一个班级人员,主要和DataBaseInfo。我已经为所有错误下载了maven库,但没有成功。我不知道为什么

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
        <bean id='data' class='com.microsoft.sqlserver.jdbc.SQLServerDriver'>  
        <property name='driverClassName' value ='java.sql.DriverManager'></property>
        <property name='dataSource' value ='jdbc:sqlserver://10.222.115.11:1433;databaseName=Test;integratedSecurity=true'></property>
        <property name='username' value='HmgDbUser'></property>
        <property name='password' value='123456'></property>
        </bean>
        <bean id='template' class='org.springframework.jdbc.core.JdbcTemplate'>  
        <property name='dataSource' ref ='data'></property>
        </bean>
        <bean id='dbi' class='test1.DataBaseInfo'>  
        <property name='template' ref ='template'></property>
        </bean>
    </beans>
Run Code Online (Sandbox Code Playgroud)

我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.sample</groupId>
    <artifactId>test1</artifactId>
    <name> Spring boots test</name>
    <version>0.0.2-SNAPSHOT</version>
    <dependencies>
    <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 -->
<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
    <scope>test</scope>
</dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter …
Run Code Online (Sandbox Code Playgroud)

java sql-server spring maven spring-boot

0
推荐指数
1
解决办法
1469
查看次数

数组内部的方法和以后的Java调用

我有一个很大的问题,我真的不知道解决方案,我似乎无法弄清楚几个小时的寻找和尝试周围的东西...

我想有一个内部有方法的数组,我想稍后用各自的索引调用它们,测试代码如下所示:

package methods;

public class Methods {
    public static void main(String[] args) {
        Methods[] methodsArray = {print_something(), something_else()};
        methodsArray[0];
    }

    public static void print_something() {
        System.out.println("Hiya!");
    }
    public static void something_else() {
        System.out.println("Something else!");
    }
}
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
61
查看次数

如何操纵场景执行的顺序

我有一些功能可以使用Gherkin和Cucumber进行测试.问题是执行是随机的,例如,第一个场景是在页面上创建元素,第二个场景是寻找它们,第三个场景是移动它们,所有测试都崩溃,因为执行过程如下:nº9firts,那么8,然后是2,然后......

我没有使用执行标签,或者如果我使用它们,我在"功能:"上面使用它来确保所有方案都在运行

任何人都可以在这里带点光明?

java selenium cucumber gherkin selenium-webdriver

0
推荐指数
1
解决办法
157
查看次数

谁创建了这些线程?

我是 Java 新手,我发现了一件有趣的事情。现在我正在学习套接字,当我调试程序时,我注意到有几个线程不是我创建的。然后我在程序的开头放置了一个断点,当我打开线程时,我可以看到属于 Socket 的所有线程。但我还没有创建它,因为它是第一行代码。我现在想知道这些线程来自哪里,以及为什么它们已经创建(如果套接字仍未创建)。

在此输入图像描述

java sockets debugging multithreading

0
推荐指数
1
解决办法
1171
查看次数

如何解决无法解决“ CELL_TYPE_BLANK”的问题?

我正在尝试在我的应用中读取xlsx文件。我正在使用Apache POI 4.0.1。我收到一个错误:

无法解析符号CELL_TYPE_BLANK“

请告诉我解决方案。

java

0
推荐指数
1
解决办法
487
查看次数

当在Java中执行while(rs.next)时,跳过Resultset的第一行

我正在尝试在java类中获取SQL查询的结果集.问题是我的表的第一行永远不会显示在我的UI上.所以我调试了它.

当第一次执行while循环时,while(rs.next)行执行然后它不进入循环,返回到while循环的开头并while(rs.next)再次执行行,现在它进入while循环并设置结果集.

但由于它没有在第一次进入循环,我的表的第一行没有设置到结果集中.

我在这里找不到问题.

我试过do{} while(rs.next)但有时它会抛出疲惫的结果集异常

    String SQL_QUERY = select * from my_table;
Statement stt = null;
stt= conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
    ResultSet.CONCUR_UPDATABLE,
                ResultSet.HOLD_CURSORS_OVER_COMMIT);

ResultSet rs = stt.executeQuery(SQL_QUERY);
if (rs != null) {
    rs.absolute(startRow); // I need to go to some specific row according to users request that is why I used this
} 

while(rs.next){
    // rs.getString...
}
Run Code Online (Sandbox Code Playgroud)

java jdbc

0
推荐指数
1
解决办法
344
查看次数