这是代码:
public static File backupDB() throws IOException {
File file = null;
file = new File("BKUP_DB_"
+ Calendar.getInstance()).replace("/", "-") + ".sql");
String executeCmd = "mysqldump -u " + "dbUserName" + " -p" + "dbPassword"
+ " " + "dbName" + " > " +file.getPath();
Process runtimeProcess;
try {
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
System.out.println("Backup created successfully");
runtimeProcess.destroy();
return file;
} else {
System.out.println("Could not create the backup");
}
} catch (Exception ex) { …Run Code Online (Sandbox Code Playgroud) 我设法将我的mysql数据库中的图像存储为Blob.(我也在使用hibernate)现在我正在尝试加载该图像并将其发送到jsp页面,以便用户可以查看图像.
这是我的struts 2动作类
Run Code Online (Sandbox Code Playgroud)import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Blob; import org.hibernate.Hibernate; import domain.post.image.Image; public class FileUploadAction { private File file; @SuppressWarnings("deprecation") public String execute() { try { System.out.println(file.getPath()); Image image = new Image(); FileInputStream fi = new FileInputStream(file); Blob blob = Hibernate.createBlob(fi); image.setImage(blob); image.save(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return "success"; } public File getFile() { return file; } public void setFile(File file) { this.file = file; } …
实际上我已经google了一点,我需要相应的SELECT命令来跟随PostgreSQL shell命令:
\dt schemaname.*
Run Code Online (Sandbox Code Playgroud)
我设法使用以下代码获取所有数据库:
Statement statement = (Statement) connection.createStatement();
ResultSet rs = statement
.executeQuery("SELECT datname FROM pg_database");
while (rs.next()) {
System.out.println("DB Name : " + rs.getString(1));
//i need another while here to list tables
//inside the selected database
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下声明,但没有运气:
statement.executeQuery("SELECT table_schema,table_name FROM "
+ rs.getString(1)
+ " ORDER BY table_schema,table_name");
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
org.postgresql.util.PSQLException: ERROR: relation "template1" does not exist
Position: 37
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at com.isiran.rayten.rg.db.bare.wrapper.PGWrap.main(PGWrap.java:64)
Run Code Online (Sandbox Code Playgroud) 我试图用eclipse运行一个简单的虚拟android项目,我也试图使用maven.我已经按照这篇文章中接受的答案的教程
这是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ir.raysis</groupId>
<artifactId>quickie</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<name>quickie</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version></platform.version>
<android.plugin.version>3.5.3</android.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>18</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
这是我的控制台日志:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects... …Run Code Online (Sandbox Code Playgroud)