Tag Archives: database

Ways to save enums in database

Questions: What is the best way to save enums into a database? I know Java provides name() and valueOf() methods to convert enum values into a String and back. But are there any other (flexible) options to store these values? Is there a smart way to make enums into unique numbers (ordinal() is not safe… Read More »

Java Embedded Databases Comparison [closed]

Questions: I intend to develop a small (Java) application for managing my finances. I believe I need to use an embedded database, but I have no experience regarding this issue. I tried to look at some of the available products, but I can’t decide which one would be more suitable for me. H2, HSQLDB, Derby… Read More »

Create MySQL database from Java

Questions: Is it possible to create a MySQL database from Java? I have only seen connection URLs examples like this where the database name is specified in the URL: String url=”jdbc:mysql://localhost:3306/test”; Connection con = DriverManager.getConnection( url, “cb0”, “xxx” ); How can I create a MySQL database when I only have a login name and password?… Read More »

How to get all table names from a database?

Questions: I’d like to retrieve all table names from a database schema, and, if possible, get all table starting with a specified prefix. I tried using JDBC’s connection.getMetaData().getTables() but it didn’t work at all. Connection jdbcConnection = DriverManager.getConnection(“”, “”, “”); DatabaseMetaData m = jdbcConnection.getMetaData(); ResultSet tables = m.getTables(jdbcConnection.getCatalog(), null, “TAB_%”, null); for (int i =… Read More »

DBCP – validationQuery for different Databases

Questions: I use DBCP pool and I want use testOnBorrow and testOnReturn to test if connection is still valid. Unfortunately I have to set property validationQuery to make it work. Question: What value should be in validationQuery? I know, that: validationQuery must be an SQL SELECT statement, that returns at least one row. Problem is… Read More »

Laravel-5 how to populate select box from database with id value and name value

Questions: I want to create a select box like the one below using illuminate\html : <select> <option value=”$item->id”>$item->name</option> <option value=”$item->id”>$item->name</option> </select> In my controller I tried this: public function create() { $items = Items::all([‘id’, ‘name’]); return view(‘prices.create’, compact(‘id’, ‘items’)); } And in my view this: <div class=”form-group”> {!! Form::Label(‘item’, ‘Item:’) !!} {!! Form::select(‘item_id’, $items, null,… Read More »

MySQL Database won't start in XAMPP Manager-osx

Questions: I downloaded XAMPP about a month ago and it was working just fine. Today I installed a voice recognition software and then restarted my computer. Ever since, MySQL won’t start in my manager-osx application. It doesn’t throw me an in the application log. This is what it says: Stopping all servers… Stopping Apache Web… Read More »

Echo from MySQL database with spaces and line breaks?

Questions: I noticed that when I submit text to my MySQL form in VARCHAR it does store line breaks. (Since they show in PHPMyAdmin). However when I echo column Text, I get everything in a single line. How can I echo values retaining line breaks? Answers: nl2br() Questions: Answers: have you tried http://php.net/manual/en/function.nl2br.php

insert contacts into database but does not want to duplicate already existing contact

Questions: I am trying to insert contacts into database but does not want to duplicate already existing contact. Not sure INSERT has WHERE CLAUSE. Any ideas? //Insert INTO contact database $user_id = userid; $sql_insert = “INSERT into `jt_members_external_contacts` (`j_user_id`,`contact_email`,`firstname`) VALUES (‘$user_id’,’$email’,’$name’) WHERE j_user_id !=$user_id AND contact_email != $email;”; Answers: You can use: INSERT … ON… Read More »