NetBeans, Connect to a Database [closed]

0

Hello, I am developing a basic program that consists of connecting netbeans to a database via mysql, the problem is that I do not know what to do, it is assumed that this database should not only be on one machine but on several machines. should the machines be connected to the network? Or is there any way to access via WIFI?

WHAT DO YOU RECOMMEND ME?

    
asked by David Ramírez 31.07.2016 в 06:53
source

2 answers

-1

You can use JDBC with the MySQL driver. To create the database you can use mysql workbench, you can manage it on the same machine.

    
answered by 31.07.2016 / 09:23
source
3
  

How to connect NetBeans to a MySQL database using Java?

There are 2 ways with NetBeans, but for both you will need the MySQL driver- JDBC .

  • With the automatic assistant (next image).

  • Downloading it from the official page and importing it into your project.

  

Where should my database be located?

Depends, if you need it only for Intranet, on a computer in your network p.e 192.168.1.100 and when you connect access to that address, if you need it for the Internet, with JDBC is more complex, hardly any hosting offers support for JDBC, you should hire a server and install it (much more cost, go out more PHP-PDO account).

  

How do I work / manage with MySQL?

There are many alternatives, the 2 most simple and popular are:

I recommend working in MySQLWorkbench and then porting it to the phpMyAdmin.

  

How do I establish a connection and make inquiries?

I have a small library that complies with this, LINK

Usage examples

tryConnection (arguments) .ping () to configure the connection and check it.

boolean response = MySQL.tryConnection(url, port, database, user, password).ping();

insert (query, parameters, OnInsert) to perform an insert SQL query.

String query = "INSERT INTO person VALUES (?, ?, ?, ?);";
String[] params = new String[]{null, "java", "mysql", "22"};

MySQL.insert(query, params, (rowsInserted) -> {
    System.out.println( rowsInserted != 0 ? "INSERT OK" : "INSERT ERROR" );
});

select (query, parameters, OnSelect) to perform a procurement SQL query.

String query = "SELECT * FROM person WHERE age > ?;";
String[] params = new String[]{"17"};

MySQL.select(query, params, (resultSet) -> {
    while (resultSet.next()) { /* Código */ }
    System.out.println( resultSet != null ? "SELECT OK" : "SELECT ERROR" );
});
    
answered by 31.07.2016 в 10:42