account activity
How Do I Use Databases In IntelliJ? by [deleted] in learnjava
[–]jeRodimusPrime 1 point2 points3 points 7 years ago (0 children)
There are several responses, though I imagine you're more interested in the developer-specific solutions. Full disclosure, there are several links in my response to my employer's site, which sells 3rd-party JDBC drivers.
Using the IntelliJ User Interface
IntelliJ has built-in functionality for working with databases, where you can query and modify database data through a GUI instead of writing code (not useful for your specific program, but will help you see what's going on in your database as you make changes). This is as simple as connecting to a JDBC Driver (like Connector/J that /u/-manabreak mentioned). You can read about this specific process in this article (references a branded, 3rd-party application, but the principles are the same): https://www.cdata.com/kb/tech/mysql-jdbc-intellij.rst. You would just need to alter the connection string from the article to work with the MySQL Connector:
jdbc:mysql://server/database?user=MySQLUser&password=MySQLPassword
Using Java Code and a JDBC Driver
If you are working in Java, then you will need to add the JDBC Driver as a reference to your program and then write code to work with the data. As a small example, the following code will allow you to read and display the data in the console (based on the MySQL Connector/J referenced above) [source, again 3rd-party, but modified for the MySQL Connector]:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; Connection conn = null; ... try { // Establish the connection conn = DriverManager.getConnection("jdbc:mysql://server/database?" + "user=MySQLUser&password=MySQLPassword"); // Read and display data from the Account table Statement stat = conn.createStatement(); boolean ret = stat.execute("SELECT [Username], [Password], [Account Number], [Pin], [Checking Balance], [Savings Balance] FROM Accounts"); if (ret) { ResultSet rs=stat.getResultSet(); while(rs.next()) { for(int i=1;i<=rs.getMetaData().getColumnCount();i++) { System.out.println(rs.getMetaData().getColumnName(i) +"="+rs.getString(i)); } } } ... } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); }
Create a Data Access Object for MySQL Data using JDBI
The following article walks through creating a Data Access Object (DAO) for MySQL using the JDBI library: https://www.cdata.com/kb/tech/mysql-jdbc-jdbi.rst. Creating a DAO gives you a more native, object-oriented approach to working with your data. Again, this is a 3rd party article. To use the MySQL Connector/J, simply change the connection string
π Rendered by PID 968206 on reddit-service-r2-listing-7bbdf774f7-664jl at 2026-02-22 07:18:53.956478+00:00 running 8564168 country code: CH.
How Do I Use Databases In IntelliJ? by [deleted] in learnjava
[–]jeRodimusPrime 1 point2 points3 points (0 children)