我正在通过url在java中读取xml,这是我的代码:
String web="example.com";
URL url = new URL(web);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(ufx);
writer.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
answer.append(line);
}
writer.close();
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
return answer.toString();
Run Code Online (Sandbox Code Playgroud)
我的问题是我使用的网址被阻止了,我想通过输入流从网上读取数据.在mozilla中删除无代理后,web在mozilla中成功打开.我如何在java中实现这一点?
我有一个基于客户端服务器的java应用程序.服务器处理来自客户端的所有请求并作出响应.我已经创建了一种在服务器上查询客户帐户的方法,但是有时候服务器返回的帐户信息与客户端请求的帐户无关.几个搜索后,我发现,这可能是线程的问题,所以我决定上解决这一问题的方法添加同步的关键字,但我的问题是,这些应用已经放缓,这是我的代码.
public synchronized List<String> queryCustomer(int AccountNumber) {
List<String> acntinfor = new ArrayList();
ResultSet rs = null;
PreparedStatement pmst = null;
Connection conn = getConnection();
try {
pmst = conn.prepareStatement("Select name,balance from tblaccount where Ac_number=?");
pmst.setInt(1, AccountNumber);
rs = pmst.executeQuery();
if (rs.next()) {
acntinfor.add(rs.getString("name"));
acntinfor.add(rs.getString("balance"));
}
rs.close();
pmst.close();
} catch (Exception e) {
e.printStackTrace();
}
return acntinfor;
}
public Connection getConnection() {
// db is class that has connection to my db
DB b = DB.getDB();
return b.getConnetion();
}
Run Code Online (Sandbox Code Playgroud)
如何提高应用程序的速度?
java ×2