when i put \dt command it s not showing me any table - java

I don't understand what's wrong and why the program is not working.
I am watching a tutorial for spring boots beginners Java framework and I got stuck at this 2 errors from the pictures . And I really don't understand why it's appearing. I have a problem with database even if i connect in terminal when i put \dt command it s not showing me any table, and another error when i run the program, and i don t understand why I am doing wrong.

\dt shows all tables on your search_path. You can specify an argument that is a pattern that matches table names. To display all tables (including system catalogs and other internal data), use
\dt *.*

Related

SQL DB2 Database Table automatic export to .csv on WIndows

I am currently training to be an application developer and am in my second month.
Now I got a task that felt impossible for me.
I have also googled since yesterday but did not find anything.
I have to insert the data from a database that I access with SQL Explorer into a .csv file. and save it on my machine
It should work automatically, but for testing it doesn't have to.
I use Eclipse and program with Java, have seen something on the Internet that it works with MySQL, but the DB2 database is connected with the SQL Explorer.
My plan is a solution, programming in java to update everyday the csv thats basically my task
Sorry if it doesn't fit here on Stackoverflow, I'm totally lost because I'm still in the trial period.
Greetings from Germany
IBM Data Server Client and driver types.
The IBM Data Server Driver Package, for example, contains the Command line processor plus utility which can run various db2 commands, statements and scripts including the Db2 EXPORT command.
Usage:
From the OS command line:
clpplus -nw user/password#host:port/database #s1.sql
The contents of the s1.sql file used as a parameter above:
SET ECHO ON;
EXPORT TO "full\path\to\my_file.csv" of del
SELECT *
FROM MYTABLE;
EXIT
You may use whatever valid SELECT statement in the EXPORT command.

ERROR: relation does not exist

So here is the problem. I am scraping some data with java and eventually i place that java into postgres database. When i run Java program, i get error ERROR: relation "table name" does not exist but when i personally write that same query in PGAdmin III, it works fine. I googled it and it's not about caps letters that most people have problems with. Here is a screenshot:
My first thought was that you were using double quotes for values, but then I looked again and realized you were assembling a query using string concatenation.
DON'T DO THAT. In addition to making these problems impossible to debug you open yourself up to sql injection.
In debugging something like this, you should first port to use placeholder syntax (which PostgreSQL's JDBC driver supports) and then, if that doesn't work, then post the server logs.

Running postgres through java

Before I get to the problem, here is what I am trying to do. So I have an assignment where you are supposed to take some sort of variable based code, interpret it, then spit out java code that connects to a database based on the latter. So basically it is java code that reads a file, and outputs a java file based on what is in the file. The output java code has to be output into a different directory (THIS IS THE PROBLEM). Also he gave us files that help us login and help with authentication. Here is the problem when I am in the directory with the output java code, and I run it, it connects to the database no problem, but when I am in any other directory, the code runs fine, but it doesn't want to connect to the database. Here are the arguments I use to run the code.
java -cp /usr/share/java/postgresql-jdbc4-
9.1.jar:/home/undergrad/3/USERNAME/testDoc/bin/a1
-Djava.security.krb5.conf=krb5.conf
-Djava.security.auth.login.config=jaas.conf a1
Since this is an assignment I can't put all my code on here, but here is the code to add something to a database. Keep in mind that this is generated code, and that that is why it looks so ugly, but the assignment is due tonight, so I can't really change that.
The stacktrace says that
the GSS authentication failed, it ended in a PSQLException. So there was an error while connecting. Yea it said it couldn't find the authentication files.

Bit confused with SQL and Tomcat

I have a huge confusion with SQL and Tomcat. You see Ive an assignment where Ive to create a WebApp (JSP) using a java class. I already did this, its a Matrix calculator that is working perfectly fine. Now I need to make a Database to store the users that log in, the type of Matrix operation they used (Sum, Substract etc), make new accounts for this users and also have a admin user. I really don't know where to start, how to connect the Database to Tomcat or is it to the Java class or the JSP? Where can I do this, use Netbeans? I read something about a driver to install but like I really don't know what it means to install it, like where and to what program.
I'm using Linux as this is what I was told to use, I'm sorry if this is too much to ask. But really my teacher just gave us an example of how to write the tables of the Database as well as the types of variables and how to edit the tables. But the rest for me is unknown. Main question is where do I start?
At first you need a database.
Maybe you want to start with MySQL: http://www.vogella.com/tutorials/MySQL/article.html
After you created a database you can connect to this database via java: http://www.vogella.com/tutorials/MySQLJava/article.html

How to Backup and Restore a MySQL Database using NetBeans?

I'm developing a software with NetBeans and I'm using MySQL as my Database server. I' planning to use two buttons as, "Backup Database" and "Restore Database" to respective functions. How to accomplish these functions? And for both functions, it would be awesome if File Chooser window is used for the functions too. Thanks in advance! :)
What about creating a dump and saving it? and then running it when you want to restore?
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
EDIT:
Well since you say you dont really know how to achieve this then ill be more specific.
mysqldumpl must be run from a commandline for this pls read this link:
http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html
your code should look something like this:
String yourCommand = "mysqldump -h localhost -u [user] -p[database password] -c --add-drop-table --add-locks --all --quick --lock-tables [name of the database] > sqldump.sql";
Runtime.getRuntime().exec(yourCommand);
After that you should have succefully saved a file with all the data of your database
the last part of the string "sqldump.sql" is the name of the file, you can set your own name with file chooser, and replace that name with the one from the user, google will help you with that.
Well first get that done
Post your code when you have it running and then we can tackle the restoring of the DB

Categories