Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception in thread main - java.nio.channels.illegalblockingmodeexception. #8171

Closed
kirtibest opened this issue Mar 27, 2024 · 4 comments
Closed

Comments

@kirtibest
Copy link

this is the sample code, which i am using to create runnable jar, and deploying on linux server, but it is giving exception in thread main - java.nio.channels.illegalblockingmodeexception. please help me.

i have added required jar for it, also i did check the java version on linux server, which is java 1.8.0_5. in eclipse also i am using jdk compliance 1.8
     import java.io.BufferedWriter;
     import java.io.FileWriter;
     import java.io.IOException;
     import java.sql.Connection;
     import java.sql.DriverManager;
     import java.sql.PreparedStatement;
     import java.sql.ResultSet;
     import java.sql.SQLException;

    public class DBToFileExporter {

    public static void main(String[] args) {
        String jdbcUrl = "jdbc:mysql://localhost:3306/your_database";
        String username = "your_username";
        String password = "your_password";
        String query = "SELECT * FROM your_table";

        try (Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
             PreparedStatement statement = connection.prepareStatement(query);
             ResultSet resultSet = statement.executeQuery()) {
            // Write records to a text file
            writeResultSetToFile(resultSet, "output.txt");
            System.out.println("Records exported to output.txt successfully.");
        } catch (SQLException | IOException e) {
            e.printStackTrace();
        }
    }

    private static void writeResultSetToFile(ResultSet resultSet, String filename) throws IOException, SQLException {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
            while (resultSet.next()) {
                // Assuming the table has columns named "column1", "column2", ...
                String line = resultSet.getString("column1") + "," + resultSet.getString("column2") + "\n";
                writer.write(line);
            }
        }
    }
}
@headius
Copy link
Member

headius commented Mar 27, 2024

Your sample code does not appear to use JRuby at all. Could you post the full stack trace?

@kirtibest
Copy link
Author

hi ,
i am getting this error
java.nio.channels.IllegalBlockingModeException at sun.nio.ch.SocketAdaptor.sendUrgentData(Unknown Source) at oracle.net.nt.TcpNTAdapter.sendUrgentByte(TcpNTAdapter.java:748) at oracle.net.ns.NSProtocol.tryUrgentByte(NSProtocol.java:1115) at oracle.net.ns.NSProtocolNIO.handleAcceptPacket(NSProtocolNIO.java:852) at oracle.net.ns.NSProtocolNIO.handleConnectPacketResponse(NSProtocolNIO.java:421) at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:262) at oracle.net.ns.NSProtocol.connect(NSProtocol.java:327) at oracle.jdbc.driver.T4CConnection.connectSession(T4CConnection.java:2645) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:795) at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:1101) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:104) oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:837) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:664)

@headius
Copy link
Member

headius commented Mar 28, 2024

I would like to help you but this does not appear to be a JRuby issue. Can you tell me why you filed this issue here?

@enebo enebo added this to the Invalid or Duplicate milestone Apr 2, 2024
@enebo
Copy link
Member

enebo commented Apr 2, 2024

Reporter can re-open if they can tie their problem into JRuby in some way. This looks like a generic Java programming problem.

@enebo enebo closed this as completed Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants