How can I access my database in xampp remotely? - mysql

I'm doing a Java project in Netbeans. I use xampp server in phpmyadmin for the database service. But each time I run the project, I have to start the xampp server. And also it is only available in my laptop. How can I configure it such that it wherever(any other computer) I run the Java application, the database gets automatically connected and data is retrieved. In the Java code, the connection is made like this:
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost/food_waste","root","");
JOptionPane.showMessageDialog(null,"Connected");
return con;
} catch (SQLException ex) {
Logger.getLogger(Make_donation.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null,"Not Connected");
return null;
}
Do I have to change anything over here as well. I'm looking for solution for a really long time. Any kind of help will be greatly appreciated. Thanks.

You will need a server where you can install database. The server can be something that you rent or some computer that you have at home that you use as a server.
You need to make sure that the database is reachable from outside (for MariaDB: https://mariadb.com/kb/en/configuring-mariadb-for-remote-client-access/).
In your connection string you need to replace "localhost" with something that is identifying your server.
If you are renting a server you can use the static IP. If you are using a computer at home as a server you will most likely have a dynamic IP. So if you want to connect from outside your home network to your database you will need something that handles the change of IPs (something like noip.com or any other dynamic DNS service). So you would need to replace "localhost" with an URL that is provided by the service you choose. And you will need to use port-forwarding if you are behind a router.

Related

jdbc sqlserver url string

I've found this in a software developed by another with j2ee spring_hibernate tomcat_v7 and jre7.
the dbURL is written as follow
dburl = "jdbc:sqlserver://remoteip\\local\\local:1433;database=dbname"
what does the double local means? when removed them the link to sql server 2008 doesn't work anymore.
simple answer to this is in the "integratedSecurity=false;"
when you want to connect to the database installed in the same machine and by the windows authentication then use "integratedSecurity=true" without login or password while you have to put the dll existant in the auth file in the jre lib directory
however if you want to use another machine (remote) this time the integratedSecurity will never work so you will have to choose the sql server connection and then absolutly use "integratedSecurity=false"
String connectionUrl = "jdbc:sqlserver://ServerName\\databaseInstance:1433;databaseName=DBSS;integratedSecurity=false;user=user;password=pass";
you may also open the sql server config manager and set TCP/IP to enabled, the ip adress (IPALL) dynamic to nothing (delete the 0) and the port to 1433 (same as the string connection) and restart the sql server service
you'll probably also need to create a firewall unbound rule for that port.
hope this will help others.

What is the connection string for Google Cloud mySQL, in node.js?

The scenario is as follows:
I am writing an node.js app locally and want it (the mySQL modul, rather) to connect to a mySQL db running on Google Cloud Platform.
I can not get the connection string right and keep getting errors. GCP holds two names for the database - one i picked, one generated, more complex. Problably I should supply one of these into the connection string as "database", the host is likely the IP address with port (or not(?)), I am not sure what the "user" should be, or if it is necessary. Not enough info on the GCP help pages or elsewhere.
tl;dr: I need the following to connect a node.js app with a mySQL module remotely to a GCP database:
var con = mysql.createConnection({
host:"11.222.333.444:3306",
user: "me"
password:"passwo3d",
database:"projectname-1528892969949:europe-west5:dbname"
});
Thank you!
The raw connection string should look something like: mysql://user:password#localhost:port/db
So I think your code should look something like:
var con = mysql.createConnection({
host:"11.222.333.444", <-- remove the port from your string
user: "me"
password:"passwo3d",
database:"dbname" <-- you have it as the instance name .. its just suppose to be the DB name
});
You can also try connecting to the instance using the cloud proxy setup. You host would just be localhost.
Finally you can always go the GCP console -> go to your instance and open up a shell. I think they print out the gcloud cmd in there and you can copy values from the console as well.
Depending on how you are pushing your code, you may have to change a few connections strings in your manifests as well. If you can share those I can help further.
For that to happen, you have to first enable remote access for your mysql on your GCP. A step by step guide is over here, you can leave the first few steps for installing mysql.

Outsystems: configuring a connection to access a MySQL database

I'm using Outsystems Service Studio to develop a web application. I need to configure a connection to access a local server database. I get "Connection String test failed: Unable to connect to any of the specified MySQL hosts." I just figured out I can't connect using "localhost", because the Outsystems server is not local, but I'm not able to find a solution. what is wrong? Other details:
MySQL Server is up and running
I selected MySQL in DBMS
Inserted my schema name
Inserted the username (with all privileges granted)
Inserted the user password
Tried both basic and advanced configuration. I inserted j"dbc:mysql://127.0.0.1:3306/mydb?user=outsystems2" as connection string parameters and I get "Connection String test failed: Keyword not supported.Parameter name: mysql://127.0.0.1:3306/mydb?user". I know this connection string can't work , but I'm not able to find a functioning one. I've read many guides about this configuration, but no solution was found. Thank you all for your time and help, feel free to ask for more details
Luciano,
Is your OutSystems environment on-premises or in the cloud? Either way, you need to make sure that this server is able to reach - it as connectivity - to your MySQL database server. Using localhost or 127.0.0.1 is pretty much the same thing as this is an address for the machine where the request is running, which is, in this case, the OutSystems server. Do you have the MySQL database on your local machine? This is not a good approach as you will need to have an address that won't change otherwise the connection won't be stable and you'd have to reconfigure it all the time.
Regards

Connecting to a MySQL DB from a WPF app

I have been trying to connect a C# WPF app with a MySQL database. The database is on a Linux machine in my network. I have a lot of experience connecting with PHP but have never done it with a .NET product. I have read through everything I have found online. I have already downloaded and installed the MySQL connect stuff and attached it to the project. I have gone into the db and made sure it would accept queries from my work PC using phpMyAdmin. I have tried a wide variety of code to call the DB. I have changed the order of everything in connStr. I have changed the labels and formatting to try everything I have come across. I am able to connect to the DB with all of the web based tools that tie to this app so I know that I have the right info. I have never posted on here so I am sorry about the formatting. Everything I have read make this sound quite straightforward. I and am currently using this:
string connStr = "user=admin;database=test;server=192.168.0.37;password=******;"; MySqlConnection conn = new MySqlConnection(connStr);
try
{
Console.WriteLine("Trying to connect to: ..." + connStr); Console.WriteLine("Connecting to MySQL...");
conn.Open();
// Perform database operations
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
conn.Close();
Console.WriteLine("Done.");
and I am getting this error:
Test.vshost.exe Error: 0 : Unable to connect to any of the specified MySQL hosts.
A first chance exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
at MySql.Data.MySqlClient.NativeDriver.Open()...
Thank you for your help on this!
When you are trying to contact a server in a home network using a basic modem/router, it can fail to recognize or pass along the port number you sent. In this case it was not recognizing or sending 3306 (default for mysql). This would make it so it would never work without SSH tunneling. After adding SSH tunneling it worked as advertised.

Connecting To Local mySql Database

Currently I am connecting to an online mySql database. I would like to switch it to a mySql database on my local hard drive and am having problems with the syntax. Unlike the online one I have no UserID or Password. Any help is appreciated. Thank you.
(mysql_real_connect (conn,"urlock.db.5513143.hostedresource.com","urlock","passxxx","useridxxx",0,NULL,0) !=0);
tried this:
(mysql_real_connect(conn,"c:\urlock.db","urlock","","",0,NULL,0) !=0);
didn't work.
That second parameter needs to be a host which represents a network connection. It cannot be an absolute file reference like you might do with MS Access files. So, you need to install MySQL5.X on your system as a service. If you've done this, verify it by either looking for an open port of 3306 (default) via a 'netstat -an' command or simply look in your services for 'MySQL ....'.
If not, download it here:
http://dev.mysql.com/downloads/mysql/
Once you get this you will be able to import the this database locally and be able to access it very similar to the online version. i.e. (mysql_real_connect(conn,"localhost","urlock","someuser","somepass",0,NULL,0) !=0);
Importing/exporting can be tricky but to point you in the right direction look into the mysqldump command.
I believe the second parameter should be the host. If it is a local mySQL, the
host is localhost.
The default username is usually 'root'.
Try this:
(mysql_real_connect(conn,"localhost","urlock","","root",0,NULL,0) !=0);
Most (if not all) installations of MySQL should have default accounts. There should at least be a root account. http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html
You'll need a CONNECTIONSTRING
SqlConnection con = new SqlConnection(connectionString);
con.Open();
If you add your database in visual studio under Dataconnections, you can see the connection string under properties
ADDED:
If its an sqllite db, you need to use an SQLCeConneciton
private static string connectionString = #"Data Source=path/to/the/database/db.sdf";
private static SqlCeConnection con = new SqlCeConnection(connectionString);