Hello im trying to output an excel file generated from a template xls using jxls library but I dont find the way to do so.
My code look like this:
ServletContext contexto = request.getServletContext();
String path = contexto.getRealPath("/lib/xlsx/plantilla.xlsx");
Conexion conexion = new Conexion();
List<Conexion> conexiones = new ArrayList<Conexion>();
ResultSet rs = CargarConsultas.ejecutarConsulta("CONS_GET_TABLA_CONEXION");
try {
while(rs.next()) {
conexion.setIp(rs.getString("ori_ip"));
conexion.setMac(rs.getString("ori_mac"));
conexion.setUrl_destino(rs.getString("url_dest"));
conexion.setSolicitud(rs.getString("time_stamp_solicitud"));
conexion.setUser_id(rs.getString("user_id"));
conexion.setSubida(rs.getString("icoming"));
conexion.setBajada(rs.getString("outgoing"));
conexion.setAutorizacion(rs.getString("time_stamp_autorizacion"));
conexion.setRenovacion(rs.getString("time_stamp_renovacion"));
conexion.setFin_sesion(rs.getString("time_stamp_fin_sesion"));
conexion.setGw_adress(rs.getString("gw_address"));
conexion.setGw_port(rs.getString("gw_port"));
conexiones.add(conexion);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File salida = new File(path);
InputStream is = new FileInputStream(salida);
try (FileOutputStream os = new FileOutputStream("salida.xlsx")) {
Context context = new Context();
context.putVar("conexiones", conexiones);
JxlsHelper.getInstance().processTemplate(is, os, context);
} catch (Exception e) {
e.printStackTrace();
}
Please let me knoew if you know how to output it and no save it to server disk.The code works fine. Thanks alot
Related
problem- only one files is save to the external storage with global name.
How to get the idea to changes the file name dynamically changes.
private String FILE_NAME = "billReceipt"; // I declared this variable as globally
encodedBase64 = response;
try{
File filePath = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/"+ file_name+".pdf");
FileOutputStream os = new FileOutputStream(filePath, true);
byte [] decodeBase64 = android.util.Base64.decode(encodedBase64, Base64.DEFAULT); //decoded the encoded string
os.write(decodeBase64);
os.flush();
os.close();
}
catch (Exception e)
{
e.printStackTrace();
}
I programmed a discord bot with java for some minecraft project I am going to make.
I bought a KVM V-Server, installed all I needed and uploaded my bot's files including my prepared sqlite database.
But the problem is: When I execute my start.sh, there is an error code.
root#5030 /home/Bot $ ./start.sh
java.sql.SQLException: No suitable driver found for jdbc:sqlite:Datenbank.db
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at de.nameddaniel.bot.main.LiteSQL.connect(LiteSQL.java:35)
at de.nameddaniel.bot.main.Main.<init>(Main.java:50)
at de.nameddaniel.bot.main.Main.main(Main.java:42)
Exception in thread "main" java.lang.NullPointerException
at de.nameddaniel.bot.main.LiteSQL.onUpdate(LiteSQL.java:64)
at de.nameddaniel.bot.main.SQLManager.onCreate(SQLManager.java:9)
at de.nameddaniel.bot.main.Main.<init>(Main.java:51)
at de.nameddaniel.bot.main.Main.main(Main.java:42)
I searched on google for help. There, in some forums, people said, that you should insert Class.forName(); before connecting to the database.
I did so but it did not help:
public static void connect() {
c = null;
try {
File file = new File("Datenbank.db");
if(!file.exists()) {
file.createNewFile();
}
String url = "jdbc:sqlite:" + file.getPath();
try {
Class.forName(LiteSQL.class.getName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c = DriverManager.getConnection(url);
System.out.println("Verbindung zu Datenbank hergestellt.");
s = c.createStatement();
}
catch(SQLException | IOException e) {
e.printStackTrace();
}
}
I am executing connect() in my Main class:
public Main() {
instance = this;
LiteSQL.connect();
SQLManager.onCreate();
try {
jda = JDABuilder.createDefault(BotToken.token).build();
} catch (LoginException e) {
e.printStackTrace();
}
jda.getPresence().setActivity(Activity.watching("dir zu."));
jda.getPresence().setStatus(OnlineStatus.ONLINE);
// audioPlayerManager = new DefaultAudioPlayerManager();
// playermanager = new PlayerManager();
cmdMan = new CommandManager();
jda.addEventListener(new CommandListener());
jda.addEventListener(new VoiceListener());
jda.addEventListener(new ReactionListener());
jda.addEventListener(new RoleListener());
jda.addEventListener(new JoinListener());
jda.addEventListener(new NicknameListener());
jda.addEventListener(new AvatarChangeListener());
jda.addEventListener(new BanListener());
System.out.println("Bot wurde hochgefahren");
// AudioSourceManagers.registerRemoteSources(audioPlayerManager);
// audioPlayerManager.getConfiguration().setFilterHotSwapEnabled(true);
shutdown();
runLoop();
}
So, how do I fix that?
If there is any information missing, please tell me. As well if you need translations.
Hope you can help me,
Daniel :D
I have been fighting with this issue since last week.still not able to solve.
i am sending file to client machine once i get in server automatically.but so many time when i handle file it throw an error that Cannot access the file because it is using by another program.
below my code
private static string SaveFileStream(string filePath, Stream stream, string Filename1)
{
string localresponse;
try
{
//this.SaveFileStream(System.Configuration.ConfigurationSettings.AppSettings[fileToPush.FileType].ToString() + "\\" + fileToPush.FileName, new MemoryStream(fileToPush.Content));
if (File.Exists(filePath))
{
File.Delete(filePath);
}
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
stream.CopyTo(fileStream);
fileStream.Flush();
fileStream.Dispose();
}
FileInfo info = new FileInfo(filePath);
ExtractFile(info);
localresponse = "Successful";
}
catch (Exception ex)
{
localresponse = ex.Message;
}
return localresponse;
}
I'm trying to get and edit the code of all the html-files in the project
i found a way to loop over all ProjectItems
IEnumerator Projects = _applicationObject.Solution.Projects.GetEnumerator();
while (Projects.MoveNext())
{
IEnumerator Items = ((Project)Projects.Current).ProjectItems.GetEnumerator();
Queue<ProjectItem> ProjectItems = new Queue<ProjectItem>();
while (Items.MoveNext())
{
ProjectItem SubItem = (ProjectItem)Items.Current;
try
{
if (SubItem.Document != null) DocumentIndex.Add(SubItem.Document);
}
catch (Exception Exception)
{
Console.WriteLine(Exception.Message);
//ignore
}
ProjectItems.Enqueue(SubItem);
}
//follow the tree down
while (ProjectItems.Count != 0)
{
ProjectItem ProjectItem = ProjectItems.Dequeue();
if (ProjectItem.ProjectItems != null)
{
foreach (ProjectItem SubItem in ProjectItem.ProjectItems)
{
ProjectItems.Enqueue(SubItem);
try
{
try
{
SubItem.Open(SubItem.Kind);
DocumentIndex.Add(SubItem.Document);
}catch(Exception Ex){
Console.WriteLine(Ex.Message);
}
}
catch (Exception Exception)
{
Console.WriteLine(Exception.Message);
//ignore
}
}
}
}
}
now i can't get to the code of the files that are not open in an editor window.
how do i get and edit the code of "not opened" projectItems?
how do i detect if a file is a code file? (eg: .cs, .html, .htm, .asp, ....
You must open the ProjectItem that you want to read or edit
DTE dte = (DTE)Package.GetGlobalService(typeof(DTE));
var project = dte.Solution.Projects.Item(1);
var projectItems = project.ProjectItems;
var anyItem = projectItems.Item(0);
Window anyItemWindow = anyItem.open()
var selection = anyItem.Document.Selection as TextSelection;
selection.SelectAll();
Console.WriteLine(selection.Text) // All code
anyItem.Document.Close() //Close Document
if you don't open the ProjectItem anyItem.Doument is null.
Note: selection.Insert("") can be used to change the code
I have another question about a "JDWP Error: 21" logged: Unexpected JDWP Error 21
I am trying to parse some XML I gather from a servlet into a J2ME MIDlet with the code below. So far unsuccessfully, I think due to the JDWP error on my HttpConnection how ever the InputStream is filled with XML and once parsed everything inside the Document is null.
Has anyone got and ideas about the JDWP error, and also does that code look like it should work?
In MIDlet I am using JSR-172 API javax.xml.parsers.*.
if(d==form1 && c==okCommand)
{
// Display Webpage
webPage = new TextBox(txtField.getString(),
"",
100000,
TextField.ANY
);
Display.getDisplay(this).setCurrent(webPage);
try
{
HttpConnection conn = (HttpConnection)Connector.open("http://localhost:8080/Blogging_Home/Interface?Page=Bloggers&Action=VIEW&Type=XML");
conn.setRequestMethod(HttpConnection.GET);
int rc = conn.getResponseCode();
getConnectionInformation(conn, webPage);
webPage.setString(webPage.getString() + "Starting....");
String methodString = getStringFromURL("");
if (rc == HttpConnection.HTTP_OK)
{
InputStream is = null;
is = createInputStream(methodString);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
Document document;
try
{
builder = factory.newDocumentBuilder();
document = builder.parse(is);
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
webPage.setString(webPage.getString() + "ERROR:" + rc);
}
}
catch(Exception ex)
{
// Handle here
webPage.setString("Error" + ex.toString());
}