Tag Info

New answers tagged

0

First, check if $id is a valid numeric value ( using is_numeric ) then finally cast the $id to type ( int ).


2

As designed with roles being a one to one relationship with users, my personal preference would be to ditch the lookup table for roles entirely and go with an enum data type in the users table. Internally in MySql it's going to be stored in a similar way, so it will not take more space. But it will return the string representation in the results making it ...


1

If you're just using plain old JDBC, you can do something like List<MyClass> results... while (rs.next()) { MyClass c = new MyClass(); c.setId(rs.getLong("THE_ID")); c.setName(rs.getString("THE_NAME")); .... results.add(c); } It's important that your class should not have any database related logic in it, that is, it should be a POJO ...


-2

There's a method using Reflection API. A quick tutorial is available in this link, While the implementation example for ResultSet can be seen here. However, be mindful of using Reflection API, since it automates a lot of things, debugging would be very difficult as it will look like that your code is working out of the box without having to do anything.


3

It sounds like you are looking to implement push notifications from your back-end service to each front-end client. Two options come to mind: WebSockets will allow your clients to maintain a persistent two-way communication channel with the server. Updates on the client can be sent along the persistent channel, and when the web-server receives a change ...


0

I would look at reworking the way you save your data. Profile can exist without picture, while picture can't exist without profile. So, once people are done with their profile, save it. Once they are done with picture, save it separately. Why separate the registration into a number of pages, if you don't save the data independently?


1

For a desktop application, it's usually better to deliver everything the end user will need in a single package. End users tend to dislike dependency requirements, because it only takes one or two conflicting packages requiring different versions of the same thing to completely ruin your day. For a single-user application, you're probably best off using an ...


2

As pvg has mentioned, a good option to use is an embedded database. The reason here is that the database can be included as a single JAR file, rather than needing to be installed on the system's user. Usually, you can access the databases using the standard JDBC API, so it really can act as a replacement for your current MySQL DB. The library will manage ...


1

If you're just learning, I recommend that you put the details of deployment to one side at first and just assume that the database will always be there and will always be in the correct format. Once you've got your application to a state where you're reasonably happy with it, then you can address your concerns regarding the database. When you do get to ...


3

You should look into one of the many embeddable pure java SQL dbs which you can embed and distribute with your app. Your existing SQL should work with those either as is or with minor modifications. Take a look at: http://hsqldb.org and http://db.apache.org/derby/


1

Rule of thumb is: If the input comes from anywhere else than from the code itself, the data provided is to be considered 'tainted'. You will have to make sure the value is what you expect and would not mess up your SQL statement (injection). Though I question why you're not using/utilizing PDO and use markers in your statement so these things are handled ...


1

Your application probably have different actions with different access levels, for example an admin will probably be allowed more things than a simple user. So you better build some data-matrix summarizing user(-roles) access-rights and check brefore treating any request if the current logged-in user (or even unlogged Guest if you happen to have such a ...


2

Just use an URL with some query parameters, like <a href="user/5?checksum=12345">Edit</a> Of course the checksum is computed, perhaps using some session cookie, and your server code has something to validate it. So if your user is abusing the system by editing the URL (e.g. replacing user/5 by user/567) the checksum should no more be valid. ...


4

I have encountered this issue several times and have found what I think is the simplest solution. Since your user can edit (personal/account?) information, I assume you have some kind of authentication system up and running. If you use sessions to keep track of recognized clients you can store the user's ID inside it. Then you can fetch the ID from the ...


0

There should not be any significant performance impact A clustered index is basically free - why not use it? Insert check for unique is an index seek It is very very fast for single or composite key Even if there performance implication for me data integrity wins every time If the data has a natural composite key then you should use a composite key ...


3

The best option is the one with the fewest things that can go wrong. This is the "the web API converts the value and inserts it into the database." There is no significant amount of computation necessary, and changes are you don't even need to convert it into decimal first. You can insert using the unhex function in MySQL (docs). If you were going for ...


2

Option 1. The string data should definitely be processed into more appropriate data types before insertion. That measurements are provided in hexadecimal is a detail of data transfer, and isn't important when it comes to storage (hexadecimal being merely a representation of numbers). Note that the script wouldn't be converting the string data to decimal ...



Top 50 recent answers are included