小编luc*_*fer的帖子

使用用户名和密码登录后如何抓取网站

我写了一个网络爬虫,它用 keyward 抓取网站,但我想登录到我指定的网站并按关键字过滤信息。如何实现。到目前为止,我已经发布了我的代码。

public class DB {

public Connection conn = null;

public DB() {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test";
        conn = DriverManager.getConnection(url, "root","root");
        System.out.println("conn built");
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

public ResultSet runSql(String sql) throws SQLException {
    Statement sta = conn.createStatement();
    return sta.executeQuery(sql);
}

public boolean runSql2(String sql) throws SQLException {
    Statement sta = conn.createStatement();
    return sta.execute(sql);
}

@Override
protected void finalize() throws Throwable {
    if (conn != …
Run Code Online (Sandbox Code Playgroud)

java web-crawler jsoup

3
推荐指数
1
解决办法
6896
查看次数

如何计算数据表中的整个行数

我正在为我的应用程序使用数据表.如何获取数据表中行的总数onload?我的代码:

$(document).ready( function() {
  $('#jobSearchResultTable').dataTable({
    responsive: true,
    "scrollY": 500,
    "scrollCollapse": true,
    "jQueryUI": true,
    "aaSorting": []
  });
)};
Run Code Online (Sandbox Code Playgroud)

如何获取数据表中的总行数 onload

javascript datatable jquery

3
推荐指数
3
解决办法
4万
查看次数

构造函数没有任何返回类型,但是如何创建对象?

根据构造函数的定义,它们没有任何返回类型,但在创建对象时我们经常做A a = new A(); 负责创建对象a.

A a=new A();
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我理解这个问题,在创建Object时构造函数实际发生了什么.

java constructor object

3
推荐指数
1
解决办法
109
查看次数

没有工作jar文件集.在Hadoop中可能找不到用户类

我正在尝试运行一个MR wordcount job.but我得到没有工作jar文件集set.i我发布stacktrace任何人都可以帮助我吗?

14/01/27 16:52:26 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
14/01/27 16:52:26 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
14/01/27 16:52:26 INFO input.FileInputFormat: Total input paths to process : 1
14/01/27 16:52:26 INFO util.NativeCodeLoader: Loaded the native-hadoop library
14/01/27 16:52:26 WARN snappy.LoadSnappy: Snappy native library not loaded
14/01/27 16:52:27 INFO mapred.JobClient: Running job: job_201401271610_0002
14/01/27 16:52:28 INFO mapred.JobClient:  map 0% …
Run Code Online (Sandbox Code Playgroud)

java debugging hadoop

2
推荐指数
1
解决办法
1万
查看次数

如何从列表生成java类中的动态表

我正在一个应用程序中工作,我必须在java类中创建一个html表,并且必须将其保存在数据库中。我正在java中创建该表,但如何在该表中生成动态行。使用3个列表。我是给予我所做的,

                              +"Interview LineUp"
                              +" <table border ='1'>"
                              +"<tr>"                           
                              +"<td>Interviewe</td>"
                              +"<td>Timing1</td>"       
                              +"<td>Timing2</td> "                              
                              +"</tr> "
                              +"<tr>"                             
                              +"<td>name</td>"
                              +"<td>timing1</td> "
                              +"<td>timing2</td> "
                              +"</tr> "
                              +"</table>"
Run Code Online (Sandbox Code Playgroud)

所以这是我在java类中使用的表,我有3个列表,其中包含3组信息,例如名称,timing1,timing2。现在我希望如果所有列表中有3个值,那么将生成3行。

列表是

List<String> interviewTimingToFrom1 = Arrays.asList(interviewTime1.split(","));
List<String> interviewTimingToFrom2 = Arrays.asList(interviewTime2.split(","));
List<String> listOfinterviewerName = Arrays.asList(intervierwName.split(","));
Run Code Online (Sandbox Code Playgroud)

就像我正在这样做

                          +"<tr>";  
                              for(int k=0;k<listOfinterviewerName .size();k++){
                              +"<td>listOfinterviewerName .get(k)</td>"
                              +}
Run Code Online (Sandbox Code Playgroud)

在那个java类中该怎么做?请有人帮忙。提前致谢

html java

2
推荐指数
1
解决办法
3万
查看次数

如何在java中的点之后拆分字符串

我要求我必须拆分具有.xls或.xlsx扩展名的字符串.我必须从本地上传文件并将其保存在我的项目目录中.我能够做到这一点.现在的要求是我必须检查上传的文件是否重复我将更改文件的名称并将扩展名附加到那个.所以我多个客户端访问该文件并尝试上传每个文件的不同名称应该保存到文件夹中.所以我这样做是为了分割Sring,但我不想要这种方法.

public class RenameFile {

    public static void main(String[] args) {

        String str = new String("Udemy.txt");

        String result[] = str.split("\\.");

        for (String ff : result) {
            System.out.println(ff);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我没有一个循环来操纵我的String.i想要一些只会剪切fileName和ext的东西,我可以将它存储在某处,然后在opeartion后我也可以追加它们.请帮助..

java

1
推荐指数
1
解决办法
2826
查看次数

如何在Apache POI中格式化XWPFTable中的单元格

我能够在Apache POI中创建一个表格,我的表格中有适当的值,但我想要的是我想减少表格中列大小的单元格大小如何做,请帮助..这就是什么我做得很好

              XWPFTable table = document.createTable(5,3);

        r3.setText("MSH Activity Score Card");
        r3.setBold(true);



        //creating first row 
        table.getRow(0).getCell(1).setText("Job ID#"); 
        table.getRow(0).getCell(2).setText("1362"); 

        //creating second row

        table.getRow(1).getCell(1).setText("Job Title#"); 
        table.getRow(1).getCell(2).setText("Global Network Architect Consultant");

        //creating third row
        table.getRow(2).getCell(1).setText("Client");
        table.getRow(2).getCell(2).setText("Carnival Corporation"); 

        //creating fourth row
        table.getRow(3).getCell(1).setText("Start Date");
        table.getRow(3).getCell(2).setText("11/13/2014");

       //creating fifth row
        table.getRow(4).getCell(1).setText("Days Old");
        table.getRow(4).getCell(2).setText("33");

        CTTblWidth width = table.getCTTbl().addNewTblPr().addNewTblW();

        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(1500));
Run Code Online (Sandbox Code Playgroud)

我正在获取一个包含数据的表,但我希望最小化其大小 在此输入图像描述

但我想要这个尺寸在此输入图像描述

java apache excel apache-poi

1
推荐指数
2
解决办法
1万
查看次数

如何使用ExecuterService一个接一个地运行两个方法作为线程

我试图执行两个方法,其中两个方法将在一段时间后逐个执行,我正在使用ExecuterService.我已经实现了部分代码但是到目前为止我无法实现的全部功能,在这里我发布了我的代码

public class ExampleExecuterService {

private static final int MYTHREADS = 3000;
public static void main(String[] args) throws Exception {

    ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);

    Object methodList[]={

            aMethod(),bMethod()
    };


    for(int i=0;i<methodList.length;i++){
        Object myList = methodList[i];
        Runnable worker = new MyRunnable(myList);
        executor.execute(worker);
    }
    executor.shutdown();
    // Wait until all threads are finish
            while (!executor.isTerminated()) {

            }
  System.out.println("\nFinished all threads");

}

public static class MyRunnable implements Runnable {

    private Object myList=null;

    MyRunnable(Object myList) {
        this.myList = myList;
    }
    @Override
    public void run() …
Run Code Online (Sandbox Code Playgroud)

java multithreading executorservice

1
推荐指数
1
解决办法
1521
查看次数

我们可以通过创建一个对象来调用类的所有构造函数

我有一个由三个构造函数组成的类,我的requiremt是我想使用一个单独的对象创建调用所有构造函数.它可能吗?

让我们说

 Class A{

        A(int a){
        }

        A(int a,int b){
        }

        A(int a,int b,int c){
        }
Run Code Online (Sandbox Code Playgroud)

我想使用一个对象创建调用所有构造函数,该怎么做?

java

1
推荐指数
1
解决办法
116
查看次数

如何用Java生成Json

我正在开发一个应用程序,我必须生成这样的json:

[
  {"title":"Culture","start":"Salary","end":"Work"},
  {"title":"Work","start":"Salary","end":"Work"}
]
Run Code Online (Sandbox Code Playgroud)

但我的代码生成json像这样:

{{"name":"Culture"},[{"name":"Salary"},{"name":"Work"}],}
Run Code Online (Sandbox Code Playgroud)

我的代码:

public class ParseJson {



public static class EntryListContainer {

    public List<Entry> children = new ArrayList<Entry>();
    public Entry name;

}

public static class Entry {

    private String name;

    public Entry(String name) {
        this.name = name;
    }

}



public static void main(String[] args) {
    EntryListContainer elc1 = new EntryListContainer();
    elc1.name = new Entry("Culture");
    elc1.children.add(new Entry("Salary"));
    elc1.children.add(new Entry("Work"));




    ArrayList<EntryListContainer> al = new ArrayList<EntryListContainer>();
    Gson g = new Gson();

    al.add(elc1);


    StringBuilder sb = new StringBuilder("{");
    for …
Run Code Online (Sandbox Code Playgroud)

java json

1
推荐指数
1
解决办法
82
查看次数