-1
我試圖從url下載內容並將其插入到我的數據庫中。我已經下載了它,但它在文本區域中顯示在一行中。我希望它在文本區域中顯示爲一個段落(如果需要,可以包裹)。這是我曾嘗試:從文本區域下載url存儲內容
String x="";
try {
conn = DriverManager.getConnection ("jdbc:mysql://localhost/mirroreddatabase", "root", "");
String data=cmbGeneNames.getSelectedItem().toString();
String sql="select * from omimmirrored where symbolGeneSymbol LIKE '%"+data+"%'";//change table
PreparedStatement pst=conn.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
//which checkboxes are checked
while ((rs.next())) {
x = rs.getString("links");
}
conn.close();
}
catch(Exception e) {
JOptionPane.showMessageDialog(null,e);
}
URL u;
InputStream is = null;
DataInputStream dis;
String s;
try {
conn = DriverManager.getConnection ("jdbc:mysql://localhost/mirroreddatabase", "root", "");
String data=cmbGeneNames.getSelectedItem().toString();
u = new URL(x);
is = u.openStream();
dis = new DataInputStream(new BufferedInputStream(is));
while ((s = dis.readLine())!= null) {
//try {
String sql = "update omimmirrored set sequence=? where symbolGeneSymbol LIKE '%"+data+"%'";
PreparedStatement statement=conn.prepareStatement(sql);
statement.setString(1, s);
statement.executeUpdate();
//which checkboxes are checked
//conn.close();
//}
} catch(Exception e) {
JOptionPane.showMessageDialog(null,e);
} finally {
try {
is.close();
} catch (IOException ioe) {
}
try {
conn.close();
}
catch(SQLException sqlException) {
} // end of 'finally' clause
}
你在取? html頁面? –
是的HTML頁面,但內容被存儲在一行,我希望它被存儲爲一個段落。 – user2944911
你應該更多地關注代碼格式,並確保在catch子句中有一些東西 - 至少是日誌記錄 –