I am trying to create a server for POP3 protocol. I'm relatively new to mySql and would like to create a simple database for storing users (username and password) and their corresponding emails(some text, not email-ID).
Example: let's say user1 has username1 and password1. I would like to create another table which points to the user1 and contains his emails there.
My main purpose is to run a query using Java and access users (using their username and password) and their emails.
How can I do this?
Take a look at this answer to know how to store passwords in database.
You can have your design something like this:
users
- id int PK
- username varchar unique not null
- passwordhash varchar not null
user_emails
- id int PK
- user_id int not null FK -> users(id)
- email varchar not null
I am not going to write down DDL for you. Check out vendor documentation for create table syntax.
Related
I have Cassandra Table as below
create table user(
id UUID PRIMARY KEY,
firstname varchar,
secondname varchar,
emailid varchar,
);
From Java - Spring Boot Im trying to access data
Optional<User> findByEmailid(String emailId);
I get error stating
It asks me to use "FILTERING ALLOWED" part of query. Is there anyway to enable this globally or I should change query/db structure?
That error is telling you that emailid is not a valid column that can be filtered on in your WHERE clause. Enabling ALLOW FILTERING or creating a secondary index on that column is one way to do this. But both of those are pretty terrible solutions (because of how Cassandra is works under-the-hood).
With Cassandra you need to take a query-based modeling approach. This means that sometimes (often) queries and tables share a 1:1 ratio. If you really need to query users by email address, then you will need to create a table to serve that query.
CREATE TABLE user_by_email(
id UUID,
firstname varchar,
secondname varchar,
emailid varchar PRIMARY KEY,
);
Then something like this will work:
Optional<UserByEmail> findByEmailid(String emailId);
And if you don't ever plan on querying the user table by id, then there really isn't a reason to use that column as your sole primary key.
I'm using javax.persistence.EntityManager in a programme. So I've a user table which use String username as the primary key in a mysql database. So when i find a value from a username i found a problem.
Sample Data :
username : MobileUser001 username : MobileUser002
I used public <T> T find(Class<T> entityClass, Object primaryKey);
So when i send "mobileuser001" , "MobileUser001" , "mobileUser001" as the primary key Persistence searched the correct data. But it gives the username what we input, Not the username with correct case in the database.
I need the correct case "MobileUser001" for any input like i mentioned above.
I was given two databases, and am supposed to create a table in a new database that stores information about the given databases.
So far I created a table in a new database. I also defined its attributes, but I am stuck on how to populate this table.
The attributes are things like 'original_db, 'original_field' etc , but I don't know how to access this information? Especially since I would need to connect jdbc to 3 databases (the new one, and the 2 old ones) at the same time. Is ths even possible?
I am new to working on databases and SQLite, so sorry if this is a stupid problem.
I would be so grateful for any advice!
What I can grasp from your question is you don't know how to insert data into it?
You could do this in your schema.sql when creating the db e.g the schema would look something like.
DROP TABLE users;
CREATE TABLE users(id integer primary key, username varchar(30), password varchar(30), email varchar(50), receive_email blob, gender varchar(6));
DROP TABLE lists;
CREATE TABLE lists(id integer primary key, user_id integer, list_id integer, name varchar(50), creation_date datetime, importance integer, completed blob);
DROP TABLE list_item;
CREATE TABLE list_item(id integer primary key, list_id integer, name varchar(50), creation_date datetime, completed blob);
then you could make a data.sql file or something with
INESRT into users VALUES(NULL, "name", ...);
and then do in the terminal
sqlite3 database.db <- data.sql
or you could start a sqlite interactive session in the same working directory as your db and manually type in the code
e.g type in
sqlite3 databasename.db
and then type in commands from there
I am creating a JFrameApplet (In Java) with a log in (SQLite) but I am struggling to understand how to compare a wanted username, against a username that is already taken:
For Example: I want the username JoeBloggs, but it is taken, how do I compare a wanted username against one already made.
I have an SQLite users.db and the field is USERNAME.
Thank you for any assistance.
Try searching up the UNIQUE constraint.
When creating a table useCREATE TABLE Users(Id INTEGER, USERNAME TEXT UNIQUE);
so if JoeBloggs is already an entry in the db trying to add it again with INSERT INTO Users VALUES(2, 'JoeBloggs'); will give you an Error: column USERNAME is not unique.
I want to create a way to authenticate users. In mysql I do:
SELECT user_id FROM customers WHERE `username` = 'the_username' AND `password` = 'the_password'
If the query doesn't return an empty resultset then user is authorized. Cassandra expects me to know the row key (user_id) upfront. How can I check all rows in a column family for existence of a username and password where I don't know the row key.
I am using Hector api to connect to Cassandra 1.2.2
Some possible solutions:
use the username as row key
create a secondary index on username
I would use the first one. If username is unique (as I assume), you don't need user_id