You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
}
}
}
The text was updated successfully, but these errors were encountered:
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)
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.
The text was updated successfully, but these errors were encountered: