Form info to database on another server - database

I have two websites; website1.com and website2.com. On website1 I have database with customer information and a neat CMS. Now I would like to make a registration form on website2 and insert that information in the database on website1.
Is this possible? Can I simply use mysql INSERT INTO~? Or do I need to use something else?

You can connect remotely to another server:
mysql -h host_name -D db_name -ppassword -c "insert into ..."

You need to allow MySQL remote connections if your websites are on different machines. Securing Remote MySQL
In both cases (remote or local), the method is the same: open a connection to website1's database and use INSERT INTO.

Related

Oracle container database 12c, connecting using JDBC

I'm trying to learn how to use Oracle Container database, and just do basic JDBC connections. I installed a dockerised version of Oracle:
https://hub.docker.com/_/oracle-database-enterprise-edition
Which according to the data sheet comes set up with a CDB database called ORCLCDB and a PDB database called ORCLPDB1.
So I figured out I can connect to it like this:
jdbc:oracle:thin:#localhost:1555:ORCLCDB
with username sys, password Oradoc_db1, and setting the special internal_logon jdbc parameter equal to "sysdba" to avoid the error "local oracle CDB: ORA-28009: connection as SYS should be as SYSDBA or SYSOPER"
And I figured out I can switch to the PDB by entering this:
ALTER SESSION SET CONTAINER=ORCLPDB1
And I can then create a new user:
CREATE USER MYUSER IDENTIFIED BY MYPASSWORD1
But then I'm stuck. I think there should be some way to connect directly to the PDB using a JDBC connect string. Every time I google about this, it talks about tnsnames blah blah, but people who use JDBC connections, are typically using Tomcat on a server, or otherwise don't have the Oracle Client installed. They expect to be able to connect to Oracle just with the thin driver installed, nothing else.
I've tried the obvious using:
jdbc:oracle:thin:#localhost:1555:ORCLPDB1
with username myuser or sys, but I always get:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
At this point I'm stuck.
You need to use a SERVICE_NAME in order to connect to an Oracle container database
Please alter your connect string like this:
jdbc:oracle:thin:#localhost:1555/ORCLPDB1
A SERVICE_NAME is denoted by a "/"
A SID (SystemIDentifier) is denoted by a ":" (not to be used)
Note! Default listener port is 1521, not sure why you specifically want a different port.
Best of luck!
Apparently the correct answer is this...
jdbc:oracle:thin:#localhost:1521/ORCLPDB1.localdomain
Then I can connect as SYS using the method above. If I want to connect as the created user, I also need...
grant create session to myuser;
and then, turn off the internal_logon jdbc parameter.

ODBC string connect to specific table

I'm connecting to a SQL Server spatial database by using ogr2ogr with the MSSQL driver.
C:\>ogr2ogr -f "GeoJSON" C:\Users\usr_m\Documents\shape_odbc.geojson "MSSQL:Driver=SQL Server;server=hksql;database=ql51pd;trusted_Connection=yes;"
as specified here and here
But I'd like to connect to download a certain table, any suggestions how I do that?
Maybe I need to fetch it in python or make another workaround.
As suggested on a side-note here. The string has to look like this:
C:\>ogr2ogr -f "GeoJSON" C:\Users\usr_m\Documents\shape_odbc.geojson "MSSQL:Driver=SQL Server;server=hksql;database=ql51pd;trusted_Connection=yes;" **<table>**

connection to nodejs SQL Server on mac

Probably a simple thing, but new to me. I could not find a post that helps with this, so I expect that I am doing something silly without knowing.
I have a SQL Server database running in Docker on mac & can easily log in to the 'sa' account.
I made another id for an application to connect to the same database.
CREATE LOGIN tisApp WITH PASSWORD='pa$Sw0rd'
SELECT * FROM sys.sql_logins WHERE name = 'tisApp'
However, when I try to connect to it, like this...
mssql -u tisApp -p pa$Sw0rd
I receive an error...
My-iMac:~ my$ mssql -u tisApp -p pa$Sw0rd
Connecting to localhost...
Error: Login failed for user 'tisApp'.
My-iMac:~ my$
The MS documentation states that an id created this way should be able to connect but...I cannot.
When I check the logs, they show:
Login failed for user 'tisApp'. Reason: Password did not match that for the login provided. [CLIENT: 172.17.0.1]
In-case this helps anyone, this was pretty simple answer after a small experiment. SQL Server was not accepting special characters through mssql for some reason. So, I updated the commands as follows and everything works perfectly now.
Of course, this is not a good password, but it works ok for now.
SQL Server:
CREATE LOGIN tisApp WITH PASSWORD='pasSw0rd'
SELECT * FROM sys.sql_logins WHERE name = 'tisApp'
Command line:
mssql -u tisApp -p pa$Sw0rd
Now, I get...
My-iMac:TIS my$ mssql -u tisApp -p pasSw0rd
Connecting to localhost...done
sql-cli version 0.6.2
Enter ".help" for usage hints.
mssql>

Netezza ODBC connection - equivalent of "use database"

After connecting to a Netezza system is there any way to switch the database? For instance, in MSSQL one could send the command use database_name in order to switch to the database_name.
Is there anything in Netezza like "use" on mssql?
http://technet.microsoft.com/en-us/library/ms188366.aspx
My reason for asking is in regards to metadata queries; I can only access _v_table of the "currently connected database".
Prior to Version 7.0 there wasn't an equivalent to USE. You had to log in to specific databases on the server however you can still access any object using. database.schema.objectname
Post Version 7.0 the equivalent is Set Catalog
SET CATALOG <database_name>
Regarding your specific inquiry. Please consider using _V_TABLE_XDB instead of _V_TABLE. This system table should provide you with a list of all tables, not just those in the database you are connected to.
If you're using NPS v7.0+, then the SET CATALOG command will connect you to a different database dynamically (without having to disconnect and reconnect). The beauty of this command is that it can be submitted from an ODBC/JDBC client as well as in an nzsql script.
In Netezza you can to other database with following command -
nzsql -u <username> -pw <password> -db <databasename> -host <netezza server IP>
hope this will help you.
As we know while executing any query in netezza we need to specify database name in connection url , which we should to make dynamic according to required database on which we have to perform operation, so in case of simple java code we can use the below Case 1) and in case of spring boot we can use below Case 2).
Case 1)
before executing any query in netezza we can execute statement as
SET CATALOG #database name#;
so it will automatically switch to database provided in set command.
Case 2)
We can switch the database in netezza with runtime switching of database
Use Apache basic data source (BasicDataSource) instead of DriverManagerDataSource while creating bean for datasource
Execute - jdbcTemplate.execute("SET CATALOG #database name#")
Before executing any query.

Connect to a heroku database with pgadmin

I would like to manage my Heroku database with pgadmin client. By now, I've been doing this with psql.
When I use data from heroku pg:credentials to connect de DB using pgadmin, I obtain:
An error has occurred:
Error connecting to the server: FATAL: permission denied for database
"postgres" DETAIL: User does not have CONNECT privilege.
How to achieve the connection?
Open the "Properties" of the Heroku server in pgAdminIII and change the "Maintenance DB" value to be the name of the database you want to connect to.
The default setup is suitable for DBAs et al who can connect to any database on the server, but apparently that isn't true in your case.
After you change the Maintenance DB name as suggested by araqnid's answer above, you should also add your database to the DB restrictions field because without this you will see thousands of databases and you may not be able to find yours in the list if the list is too long.
More details here - How to hide databases that I am not allowed to access
This is for pgAdmin 4
In order to connect pgAdmin to your database (postgres instance in Heroku), do the following:
Login to Heroku, and select the application in which you have the database
Select the Resources tab and then click on "Heroku Postgres Ad-on" (see below). This will open up a new tab.
Select the Settings tab and then click on "View Credentials..." (see below)
You will get the following information that you will use in pgAdmin:
Go to pgAdmin, and create a new server
In the General tab, give a useful name
In the Connection tab, fill the info you got at Heroku
In order to avoid seeing thousands of databases, you need to add your database name to DB restriction in the Advanced tab (see below)
We require SSL for connections outside Heroku. Please verify whether you're forcing SSL in your client.
Answered more thoroughly here: Connecting pgAdmin3 to Postgres on Heroku
We don't allow connections to the postgres database, so be sure to set Maintenance DB to your database name, and be sure to use SSL.
Change the Maintenance Database to the name of your Database, e.g. dva70000p0090. This should work.
the db password local isnt the same db password heroku. please check the heroku ip postgtres address and extrac

Resources