public Connection databaseConnection = null;
public Statement statement = null;
public ResultSet ipdata=null;
public void createConnection(){
try {
Class.forName("com.mysql.jdbc.Driver");
//String sourceURL = new String("jdbc:mysql://127.0.0.1/test");
//databaseConnection = DriverManager.getConnection(sourceURL,"root","root123");
String sourceURL = new String("jdbc:mysql://127.0.0.1/"+database);
databaseConnection = DriverManager.getConnection(sourceURL,user,passwd);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void getData(){
try {
statement = databaseConnection.createStatement();
ipdata = statement.executeQuery("SELECT * FROM "+table);
int i=0;
while(ipdata.next()) {
System.out.println(i++);
System.out.println(ipdata.getString("request_ip"));
System.out.println(ipdata.getString("request_object_url"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
No comments:
Post a Comment