MySQLSyntaxErrorException: Unknown database - JDBC - Java EE - java

Really odd issue here, it was working a few days ago. I create a new database for a new project and I go to run it and I get the following error
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database
So I went back to my older projects and tried to run them. Same error.
The database is definitely there, it's named correctly, i'm using user "root". MySQL is started, I can interact with it in terminal... any particular reason I may be getting this error?
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/twittermap","root","");
In terminal:
select CURRENT_USER()
will return root#localhost
SELECT DATABASE() FROM DUAL;
returns twittermap
show variables like 'port';
returns 3306
If any more information is required please let me know and I will post it immediately. This is most likely a simple fix but I just can't wrap my head around it. Thanks all, really appreciate the help!
EDIT: I ran netstat -tnl and 127.0.0.1:3306 is NOT listed.. ?

Just write like this:
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/twittermap","root","");

Related

Cassandra Command Line Tutorial

I am trying to run the command line tutorial for Cassandra and am running into an error. This is what I ran.
bin/geomesa-cassandra ingest --contact-point localhost --key-space mykeyspace --catalog mycatalog --converter example-csv --spec example-csv examples/ingest/csv/example.csv
This is what I get in return.
What would cause this?
You need to specify the contact point as host:port. See the documentation for the connection parameters. I opened a ticket to improve the error handling for an incorrectly formatted contact point, so that the error will be more obvious.
Thanks,

MySQL TINYINT(1) mysteriously mapped to Java type Integer

I'm stuck in a huge and old project (j2sdk 1.4.2, Tomcat 4.1.29, MySQL 5.0.51a) that I need to install a new development environment for at work.
I've got a MySQL DB that is accessed by my Tomcat, which treats request from my Java application. In that DB, some tables contain boolean values that are needed by my application.
So, in the application, a prepared statement is made, parameters are added to it, then the request is launched and the result set of this request is stored inside of a custom SQLResult object (that is part of a custom framework made by my company, can't do anything 'bout that - though, it is quite similar to a classic java.sql.ResultSet object).
Here's the problem: when the java application request some data that are stored in the DB as TINYINT(1), those data are returned to the java application as java.lang.Integer, not java.lang.Boolean, as I would like to.
Note: the JDBC connector version used by the Tomcat server is mysql-connector-java-3.0.11-stable.
What I tested so far (without result):
upgrade/downgrade the MySQL connector
added tinyInt1isBit=<true/1> as the end of my connection string
upgrade/downgrade the MySQL DB, always with the same data dump I have been given along the source code
plenty other things I couldn't even remember, because I tested so much things :-/
I'm pretty sure now that the problem comes from the MySQL JDBC connector used by the Tomcat server. Thus, when I changed the version of the connector, nothing else was working anymore (meaning, couldn't even connect a user).
Any ideas?
EDIT: I forgot to precise that, in another part of the java application, request for data stored as DECIMAL are returned as java.lang.String! This is also a major problem I have to solve, but I think the two are linked to the same cause.
From Connector/J documentation
MySQL Type Name: TINYINT
Return value of GetColumnClassName: TINYINT
Returned as Java Class: java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.
Please note: or java.lang.Integer if not. Check the property tinyInt1isBit and possibly change it.
If you already did it try to restart the mysql server.
So, after a complete week of work, I managed to found the solution. Beware, that was kind of stupid.
I was right when I thought the MySQL connector was the source of my problems. I decided to retry everything I tried until today to solve the situation, and so I slightly upgraded the connector (from v3.0.11 to v3.1.14). Then I re-launched the problematic DB requests and noticed an ERROR log I didn't see before in my Tomcat logs: the DB name specified was not correct (something like myDB\?autoReconnect=true...). Indeed, a \ had been wrongfully inserted before the connection arguments part.
I removed the guilty \ from the connection string, relaunched my Tomcat, and... tadaaa! My problems were solved!
However, I did test with the old MySQL connector (v3.0.11) and it still returns TINYINT(1) as java.lang.Integer and DECIMAL as java.lang.String. So I guess the client upgraded its MySQL connector on its production Tomcat without warning me.
Anyway, thank you all for your suggestions. Guess I'll read server logs more carefully when I debug in the future :-)

Error connecting to Oracle database using JDBC [duplicate]

I am new to Oracle, and am trying to run a simple example code with Java, but am getting this error when executing the code.. I am able to start up the listener via CMD and am also able to run SQL Plus. Can anyone give me a hand and tell me what I might be doing wrong?
Update:
I am using JDBC.
Database is local, and I actually had it working but it stopped working just today. I'm not really sure why though. Would you mind giving me some procedures to follow by since I don't know much.
Either:
The database isn't running
You got the URL wrong
There is a firewall in the way.
(This strange error message is produced by Oracle's JDBC driver when it can't connect to the database server. 'Network adapter' appears to refer to some component of their code, which isn't very useful. Real network adapters (NICs) don't establish connections at all: TCP protocol stacks do that. It would have been a lot more useful if they had just let the original ConnectException be thrown, or at least used its error message and let it appear in the stack trace.)
I had the same problem, and this is how I fixed it.
I was using the wrong port for my connection.
private final String DB_URL = "jdbc:oracle:thin:#localhost:1521:orcll"; // 1521 my wrong port
go to your localhost
(my localhost address) : https://localhost:1158/em
login
user name
password
connect as --> normal
Below 'General' click on LISTENER_localhost
look at you port number
Net Address (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522))
Connect to port 1522
Edit you connection
change port 1521 to 1522.
done
Another thing you might want to check that the listener.ora file matches the way you are trying to connect to the DB. If you were connecting via a localhost reference and your listener.ora file got changed from:
HOST = localhost
to
HOST = 192.168.XX.XX
then this can cause the error that you had unless you update your hosts file to accommodate for this. Someone might have made this change to allow for remote connections to the DB from other machines.
I figured out that in my case, my database was in different subnet than the subnet from where i was trying to access the db.
I had this error when i renamed the pc in the windows-properties. The pc-name must be updated in the listener.ora-file
Most probably you have listener configured wrongly, the hostname you specify in connection string must be the same as in the listener.
First check the Firewall and network related issues.
Check if Oracle Listener service is available and running. If not you may use Oracle Net Configuration Assistant tool to add and register new listener.
If the above steps are ok then you need to configure Oracle Listener appropriately. You may use Oracle Net Manager tool or edit “%ORACLE_HOME%\network\admin\listener.ora” file manually.
There are 2 options that need to be considered carefully:
Listening Locations associated with the Listener – Hostname(IP) and Port in Listening Location must exactly match the ones used in the connection string.
For example, if you use 192.168.74.139 as target hostname, then there must be Listening Location registered with the same IP address.
Also make sure the you use the same SID as indicated in Database Service associated with the Listener.
https://adhoctuts.com/fix-oracle-io-error-the-network-adapter-could-not-establish-the-connection-error/
IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=iKQM6lBbSLiArrYuDqud8A==)
if you are facing this issue
1- make sure you have downloaded oracle databases like oracle 11g,19c, 21c, or any latest databases.
2- search for services in your computer or type win+r then services.mis then search for oracleservice you will find orcl or xe or any other sid like oracleserviceorcl;
after that you can test your connection using sql developer, sql plus or cmd
To resolve the Network Adapter Error I had to remove the - in the name of the computer name.
In my case, I needed to specify a viahost and viauser. Worth trying if you're in a complex system. :)
For me the basic oracle only was not installed. Please ensure you have oracle installed and then try checking host and port.
I was having issues with this as well. I was using the jdbc connection string to connect to the database. The hostname was incorrectly configured in the string. I am using Mac, and the same string was being used on Windows machines without an issue. On my connection string, I had to make sure that I had the full url with the appending "organizationname.com" to the end of the hostname.
Hope this helps.
Just try to re-create connection. In my situation one of jdbc connection stopped working for no reason. From console sqlplus was working ok.
It took me 2 hours to realize that If i create the same connection - it works.

Play! framework - Cannot connect to database

this is the error I get when I'm trying to connect to my local postgresql db:
Cannot connect to database [default]
this is the database configuration. I'm convinced that there is not typo (fat finger error):
db.default.url="postgres://localhost:5432/myproject/"
db.default.user="postgres"
db.default.pass="mypassword"
db.default.driver="org.postgresql.Driver"
db.default.initSQL="SELECT 1"
where is the problem? with pgAdmin I can connect easily
p.s.
I'm using ubuntu. I've noticed that in order to change to postgres user
I must use "su", otherwise it fails changing the current user.
is that has something to do with play! failure to connect my db?
thanks
There might be two things wrong or at least dubious in your setup.
First: The postgres:... URL syntax is not a plain JDBC URL. This format is not understood by the PostgreSQL JDBC driver. See this answer to a similar problem.
Second: You are trying to use the PostgreSQL superuser account for Play. The superuser account should be used only for administrative work, but not "normal" work. Especially not for work which includes public access to the DB via some webfrontend. Any SQL-Injection attack gives the attacker the golden key to your database - including the nuke to wreck your complete DB cluster at once or install any backdoor into you DB server.
So I recommand, that you create a new user which you configure in your Play! settings.
That said: The default password for the postgres user is not set on Ubuntu. This setup allows login to the DB user only from the same OS user. How you can fix this is explained in this answer.
If these two tips don't help: The error you quoted is very vague. There must be more detailed error logs somewhere. Please find them and attach them to your question with the "edit" button.
This is not an answer directly to your question, but I had the same error message and came here via Google. Using Scala Play 2.3, I had
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true
which needed to be
db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true
I accidentally left the quotes around the driver name out. Now it works perfectly.
here is my conf, it works:
db.default.url="jdbc:postgresql://127.0.0.1:5432/dbname"
db.default.driver="org.postgresql.Driver"
just add the jdbc: before postgresql in db.default.url.

Connecting to a MySQL database

I have created a MySQL database. I am building a GUI in java. How can I connect this Java software to the database?
First, you need to add the mysql jdbc driver jar to your project, then you would create a connection as follows:
String url = "jdbc:mysql://yourhost:port/dbname";
Class.forName ("com.mysql.jdbc.Driver"); // to load the driver
Connection conn = DriverManager.getConnection (url, userName, password);
Here yourhost is the name or ip address of the server, port is the port number to which the mysql server is bound, dbname is the name of your database.
using any of the miriad of Java/SQL API, so you can perform normal SQL queries. JDBC is a start
Start using JDBC, it's best for start. Take a look on some tutorials
http://www.tutorialspoint.com/jdbc/jdbc-quick-guide.htm
http://www.jdbc-tutorial.com/
this post has helped me quite alot!
I'm quite 'disapointed' and 'suprised' I suppose that Java doesn't have the fuctionatly of connected to online databases built in.
One thing that would make it better, and please tell me the followings true: the fact that users of my software don't have to do anything special like install any drivers?
I've already added one answer - asking a question but the comments/reply's I got seem to be a bit off topic and now I've commented back asking for the answer to my original question no one seems to be answering (Have a look for your self - see what I mean)
So, the orignal question :: The only thing I want to know;
Do the users of my software I made using JDBC have to do anything special regarding JDBC, or is just me who needs to have JDBC while writting the program?
PS Sorry if I'm a bit pushy or doing things that your not supposed to do - I'm new to this community!

Categories

Resources