I know very little about databases. Is it possible to make a query to a sql server with a URL? if yes, can you provide a sample explanation.
Also another question, what is the best way to handle this situation in code?
No, it is not possible to query a database via URL. But you can build one on your own.
On your server, receive the query via URL and run the query and return the output of the query to the user.
But this is highly discouraged, as anyone can access your database, unless you add security measures, by asking for username/password in the URL itself.
ya you can do so by passing thee sql query as get value of the link
eg. http://www.site.com/?query=Select * from tbl
n then use that query inside of the page
by just connecting db n executing it..
you will get your ans as json object
thats it
Related
Basically i need to know if there is any way to get the current schema name using Mybatis.
The DB engine I'm using is MySQL
The most easy way, for which you don't even need to do anything MyBatis-specific, would simply be a query:
SELECT DATABASE();
This should, according to the documentation, return the current database.
Alternatively, you should be able to get the Configuration from your SqlSession via getConfiguration() and get it from there somewhere, perhaps from the environment which allows you access to the DataSource, but you will probably need some database-specific code there.
I have a MYSQL database with a query. The query only works if I manually type in the data with MYSQL Admin or with the following statement $sn="x-xxx"; It will not return results if i pass $sn to the database from a form even though the $sn get inserted into the database just fine. I can look at the database and see that it's there. Not sure if why the query would only pull down the records I manually imputed.
Thanks for the help guys. I found that by passing the variable from page to page that a space was being added to the variable. I used:
$sn=preg_replace('/\s+/', '', $sn); and var_dump($sn); to strip the space and to check what was being posed. Wow 5 full days trying to find this. Thanks to everybody who answered.
Questions
What is/are the most cheapest SQL-Statment(s) (in terms of Processing Overhead/CPU Cycles).
Are there (this will most likely be DB-Client specific) any Statments that are evaluated directly by the client and even do not go to the database server?
The result doesn't matter, if an empty statement (which produces an SQL Error) is the cheapest OK, then this is good too. But I am more interested in non Error Responses.
Background:
I have an application that queries a lot of data from the DB. However I do not require this data. Sadly, I have no possibility to skip this query. But I have the possibility to change the SQL Query itself. So I am trying to find the cheapst SQL Statement to use, ideally it should not even go to the SQL Server and the SQL-Client Library should answer it. I will be using MySQL.
UPDATES (on comments):
Yes, it can be a No-Operation. It must be something I can pass as a regular SQL String to the mysql client library. Whatever that string could be, is the question. The goal is, that this Query then somehowreturns nothing, using the least Resources on the SQL Server as possible. But in idealcase the client itself will realize that this query doesnt even have to go to the server, like a version Check of the client library (OK I know this is no standard SQL then but maybe there is something I do not know about, a statement that will be "short circuited/answered" on the client itself).
Thanks very much!
DO 0
DO executes the expressions but does not return any results. In most respects, DO is shorthand for SELECT expr, ..., but has the advantage that it is slightly faster when you do not care about the result.
i facing problem while writing database query in jsp that uses a string patterns.
example : i want to know whether a table exists or not in database, the table name can start with any name but ends with " session". eg : guru_session, hellosession, etc.
how can write that query ?
here is my code in jsp :
DatabaseMetaData md = con.getMetaData();
ResultSet rs = md.getTables(null, null, "table_name_here", null);
i tried using "*session" to check a table name "guru_session" exists or not .
but its not working. give me some help here.
The first thing, javascript and java are different languages. In your case javascript works in a client browser, when java runs on a server.
There is a way to interact between client and server via javascript asynchronously in background. Your task appears a bit strange, and in my experience when a developer needs to make non-elegant decisions upon development process, then there's something wrong with the whole application structure. It could be useful to reconsider the architecture of your solution.
It depends on a database platform, but table names are stored in system tables. Check system tables for your particular RDBMS platform, and query these system table(s) to get information you need. You can do it asynchronously in background via ajax calls to a servlet on the server and act accordingly on the client's browser.
Good luck.
You need to run a query like that:
SELECT *
FROM information_schema.tables
WHERE table_name LIKE '%session';
I think that this approach can help you.
Is there a way to allocate a default database to a specific user in MySQL so they don't need to specify the database name while making a query?
I think you need to revisit some concepts - as Lmwangi points out if you are connecting with mysql client then my.cnf can set it.
However, your use of the word query suggests that you are talking about connecting from some programming environment - in this case you will always need a connection object. To create connection object and in this case having default database to connect to will lead to no improvement (in terms of speed or simplicity). Efficiently managing your connection(s) might be interesting for you - but for this you should let us know exactly what is your environment.
If you use a database schema you don't need to specify the database name every time, but you need to select the database name.
The best thing to do would be to use a MySQL trigger on the connection. However, MySQL only accepts triggers for updates, deletes and inserts. A quick Google search yielded an interesting stored procedure alternative. Please
see MySQL Logon trigger.
When you assign the permissions to every user group, you can also specify, at the same file, several things for that group, for example the database that users group need to use.
You can do this with a specification file, depending on the language you are working with, as a simple variable. Later, you only have to look for that variable to know which database you need to work with. But, I repeat, it depends on the language. The specification file can be an XML, phpspecs file, or anything like this.