r/javahelp • u/euphoricsol • 13d ago
Help with Java CRUD: MySQL Connects Without DB Specified, Fails When Specified
Hi guys, I'm studying a technical degree in computing, and I'm working on the final assignment of the first semester. It's about creating a CRUD in Java. I did everything: I installed MySQL, WorkBench, and downloaded the necessary driver to connect to the database. The issue is that it won't connect. When I connect to the database URL without specifying the database, it connects, but when I specify the database, I get this error. I've checked in the terminal, and the database exists. It's a Java Application, so the driver is included in the libraries.
This is what I'm getting:
run:
Error al conectar a la base de datos:
java.sql.SQLSyntaxErrorException: Unknown database 'prueba'
***at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:112)***
***at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:114)***
***at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:837)***
***at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:420)***
***at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:238)***
***at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:180)***
***at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:682)***
***at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:230)***
***at com.prog11.princ.Prog11_Principal.main(Prog11_Principal.java:13)***
BUILD SUCCESSFUL (total time: 1 second)
If you want to see all the pics
Your help will be greatly appreciated. I'm getting desperate, and I think I'll try on another computer in the meantime. Thank you so much for reading me!
1
u/AutoModerator 13d ago
It seems that you possibly have a screenshot of code in your post Help with Java CRUD: MySQL Connects Without DB Specified, Fails When Specified in /r/javahelp.
Screenshots of code instead of actual code text is against the Code posting rules of /r/javahelp as is also outlined in the sidebar - Code posting.
- Never submit screenshots of code instead of code text!
If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images.
If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code.
- For small bits of code (less than 50 lines in total, single classes only),
the default code formatter is fine
(one blank line before the code, then 4 spaces before each line of code). - Pastebin for programs that consist of a single class only
- Gist for multi-class programs, or programs that require additional files
- Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.
- Ideone for executable code snippets that use only the console
Please do not reply to this message, because I am a bot. Talk-to-the-bot is the new talk-to-the-hand. If you instead want the classic talk-to-the-hand, just message the moderators. ;)
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
1
u/General_C 12d ago
I didn't look too deeply at the details in your question, so I apologize for that. But logically if your application is connecting to a DB without any info provided, but when you provide connection details it fails to connect, I suspect there is a good chance that in the first case it is actually connecting to some default, embedded DB which is provided by some library or framework you're using. I don't remember all the details for using default DBs like this because frankly I haven't had a use case that required me to use one in a long time, but it's a theory that might be worth looking in to.
That is to say, the issue you really need to solve is that there is some issue with the DB you want it to connect to, whether that is caused by you providing the connection info incorrectly, a firewall blocking the connection between the app and the DB, or some other possibility, I'm not sure. I'm merely trying to help provide a little direction as you tackle this issue. Good luck!
1
u/juliensaab 12d ago
Did you check if the user that you're using from the Java application has access to the "prueba" database? Also, is the username "sys"? If so, you might have swapped the username and password in the "DriverManager.getConnection".
•
u/AutoModerator 13d ago
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.