Note that there are some explanatory texts on larger screens.

plurals
  1. POcompare filename to an integer
    primarykey
    data
    text
    <p>I have a database in <code>mysql</code> with field <code>userId, userName etc,.</code> from here I'm retrieving <code>userid</code> based on some criteria. </p> <p>I have a folder with files and name of the file is some <code>userId</code> . I want to compare retrieved <code>userId</code> with those files and if they match further process those files.</p> <p>I tried this code but its giving number format exception. not able to understand why?</p> <pre><code>package read; import java.io.*; import java.util.*; import java.sql.*; public class read1 { static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/test"; static final String USER = "root"; static final String PASS = "root"; public static void main(String args[])throws Exception{ Connection conn = null; Statement stmt = null; try{ Class.forName("com.mysql.jdbc.Driver"); System.out.println("Connecting to database..."); conn = DriverManager.getConnection(DB_URL,USER,PASS); System.out.println("Creating statement..."); stmt = conn.createStatement(); String sql; sql = "SELECT userId FROM profile1 where friendCount &gt;200 AND statusCount &gt; 200"; ResultSet rs = stmt.executeQuery(sql); processing p = new processing(); File directory = new File("/home/abc/tweet"); //get all the files from a directory File[] fList = directory.listFiles(); while(rs.next()){ int uid = rs.getInt("userId"); System.out.print("ID: " + uid +"\n"); for (File file : fList){ if(file.isFile()) System.out.println(file.getName()); if(Integer.parseInt(file.getName())== uid) p.process(file.getName()); } } } catch(SQLException e){ e.printStackTrace(); } } } class processing{ void process(String filename)throws Exception{ FileReader fr = new FileReader("/home/abc/tweet/"+filename); BufferedReader br = new BufferedReader(fr); FileWriter wr = new FileWriter("/home/abc/newtweet/"+filename); String s; String str="Text:"; String a[]; BufferedWriter bw = new BufferedWriter(wr); while ((s = br.readLine()) != null) { if (s.startsWith("Text:")) { // worked a= s.split(" "); for(int k=1;k&lt;a.length;k++) bw.write(a[k]+"\n"); // worked } } br.close(); bw.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload