sql 1 « mysql « Java Database Q&A





1. java.sql.Connection extension for SSH    stackoverflow.com

I have a MySQL database behind a firewall which can only be accessed via an SSH connection. Does anyone know of an implementation of java.sql.Connection which would allow me to make ...

2. LINQ for Java tool    stackoverflow.com

Would a LINQ for java be a useful tool? I have been working on a tool that will allow a Java object to map to a row in a database. ...

3. MySQL and SQLite differences in SQL    stackoverflow.com

I'm writing java application that is using both SQLite and MySQL using JDBC. Are there any differences in SQL for those databases? Can I use same queries for both SQLite and MySQL, ...

4. How to write a null safe compare "<=>" in pure SQL?    stackoverflow.com

In Mysql there is a compare operator that is a null safe: <=>. I use this in my Java program when creating prepared statements like this:

String routerAddress = getSomeValue();
String sql = ...

5. ejb sql [select * from where A & 1]    stackoverflow.com

i will use a query like this in ejb ql:

Select * from whe A&1;
But i have the following error:
line 1, column 171: unexpected char [&].
How can i use this operator to ...

6. Running a .sql script using MySQL with JDBC    stackoverflow.com

I am starting to use MySQL with JDBC.

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql:///x", "x", "x");
stmt = conn.createStatement();
stmt.execute( "CREATE TABLE amigos" +
            "("+
  ...

7. How to get the results of WHERE conditional evaluations in the result set?    stackoverflow.com

The PROBLEM

I have a query like this:
select a.id from a join b on ( a.id = b.my_a ) join ....
where 
    ( /* complex and expensive conditional */ ...

8. Question about SQL catalogs - What exactly are they?    stackoverflow.com

Something that has been puzzling me for a bit now, and an hour or two of googlin' hasn't really revealed any useful answers on the subject, so I figured I'd just ...

9. mysql propogate sql exception to java program    stackoverflow.com

i have a java program that is calling a Mysql stored procedure that is rolling back when it gets an SQLException. When i added the rollback (exit handler) to the ...





10. Insert 50 thousand record in MySQL    stackoverflow.com

I want to insert 50 000 records into MySQL through a web service written in Java but only 20 000 records are getting inserted. I dont think there is size (number of ...

11. How to read data from an XML file and store it into database (MySQL)?    stackoverflow.com

I need to get data from an XML file and store it into a MySQL Database. I am thinking of using a SAX Parser for parsing the data but I am ...

12. Java and SQL : return null or throw exception?    stackoverflow.com

This is another debated subject, but this time i am searching only for the simple and documented answers. The scenario : Let's assume the following method:

 public static Hashtable<Long, ...

13. How to store data into MySQL database?    stackoverflow.com

I have created a java application which stores data into MySQL database. For that I have done the following things:

  1. I have installed MySQL database on my computer.
  2. I have created a database on ...

14. Few questions from a Java programmer regarding porting preexisting database which is stored in .txt file to mySQL?    stackoverflow.com

I've been writing a Library management Java app lately, and, up until now, the main Library database is stored in a .txt file which was later converted to ArrayList in Java ...

15. " INTO OUTFILE " statement terminated without completion locks the file    stackoverflow.com

i am creating a csv by using "INTO OUTFILE" statement for a mysql database. the database is huge 0.4 million records. i am using java program from eclipse to connect to ...

16. Dealing with ugly SQL in Java    stackoverflow.com

Here goes a SQL-Java coding style question... How do others here deal with creating complex custom queries in Java cleanly? I am speaking of the seemingly simple task of preparing a string which ...





17. mysql's current_timestamp for java derby    stackoverflow.com


In MySQL I can easily set the default value of a timestamp field to be the current time

fieldname timestamp not null default current_timestamp
Does anyone know how to do the same thing ...

18. sql statement "into outfile" not working with jdbc    stackoverflow.com

I am attempting to add an "export to CSV" feature to a webapp that displays data from a MySQL database. I have a written a "queryExecuter" class to execute queries ...

19. Which method should I go with; Indexing MySQL db with SOLR    stackoverflow.com

I have a classifieds website, with approx 30 categories of classifieds. I am on the stage where I have to build MySQL tables and index them with SOLR. Each row in a table ...

20. Close SQL connection Java Webservice    stackoverflow.com

I am programming a WebService in Java that create and call this class :

    public class Manager{

        private Connection aConnection;


  ...

21. Do I need to normalize this MySQL db?    stackoverflow.com

I have a classifieds website which uses SOLR to search for whatever ads the user wants to search for... SOLR then returns the ID:s of all the matches found. I then ...

22. Wrong number of database records is output by a Java program    stackoverflow.com

I have a table in mySQL and has 3 line which has name ,address,Telephone,Age,Charge. in two of them the names are "Adam" and the last row is "Abas" ,i don't know ...

23. SQL command line    stackoverflow.com

my friend wants from me to write two queries for him but really I don't know ,would you please help me? also there is a table with two column (String Telephone and ...

24. Anybody care to explain "Tokenized Field" in terms of Databases?    stackoverflow.com

I am reading about SOLR and indexing a MySQL database into SOLR. What do they mean by "tokenize" and "un-tokenize"? And what does it mean when fields are "normalized"? I know how and what ...

25. Java: Trouble connecting to MySQL    stackoverflow.com

I'm writing a desktop java app on that I want to connect to a MySQL database on a server. Here is the code to do that:

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

private static ...

26. How can I implement this functionality into SOLR?    stackoverflow.com

I have a classifieds website, and users may for example search for cars. When searching for a car, there are a number of endings in their names as you all probably know. For ...

27. SOLR commit and optimize questions    stackoverflow.com

I have a classifieds website. Users may put ads, edit ads, view ads etc. Whenever a user puts an ad, I am adding a document to solr. I don't know however when to commit ...

28. How to overcome "java.sql.SQLException: Too many connections" exception?    stackoverflow.com

I have a simple web application written in java which has servlets accessing the Mysql Database to generate reports. The report generation happens very frequently. I am using the apache commons ...

29. Alternative of Storing data except databases like mysql,sql etc    stackoverflow.com

I had completed my project Address Book in Java core, in which my data is stored in database (MySql). I am facing a problem that when i run my program on other ...

30. Multi database schema export    stackoverflow.com

I'm writing a project that will make use of mySQL or Derby (it must work in both situations). To solve this I'm using Hibernate and it works nicely, but for a ...

31. java cms(opencms) and my SQL configuring problem    stackoverflow.com

i have installed open cms on my local machine and it perfectly works fine. But in order to work it corre,ty it is mentioned that i have to modify the my.ini file ...

32. Speed up multiple JDBC SQL querys?    stackoverflow.com

I'm working on a shortest path a* algorithm in java with a mysql db. I'm executing the following SQL Query approx 300 times in the program to find route connections from ...

33. SEC_TO_TIME() convert to java.sql.Time error    stackoverflow.com

hi I have a aggregate column present the microsecond, a report(with jasper) have to show HH:mm:ss of this indicator What I did is using SEC_TO_TIME(sum(col)/1000) , but when mapping to java.sql.Time, i ...

34. How do I get the median/mode/range of a column in SQL using Java?    stackoverflow.com

I have to get the median, mode and range of test scores from one column in a table but I am unsure how to go about doing that. When you connect ...

35. How to save Map objects in Java to MySQL database    stackoverflow.com

I have Java Map (out of Strings and Ints) objects that I want to save to a database. Is there a standard way to go about this task? Is there a way ...

36. sql jdbc getgeneratedkeys returns column "id" not found, column type unknown    stackoverflow.com

I want to retrieve the most recently updated value in the table using an insert query. these are the datatypes in my sql table.

int(11) // primary key auto increment, not being assigned ...

37. java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2)    stackoverflow.com

@WebMethod(operationName = "SearchOR")

  public  SearchOR getSearchOR (@WebParam(name = "comp")
  String comp, @WebParam(name = "name")
 String name) {
            ...

38. java.sql.SQLException: Parameter number X is not an OUT parameter    stackoverflow.com

I'm struggling with getting the result OUT variable from a MySQL stored procedure. I get the following error:

java.sql.SQLException: Parameter number 3 is not an OUT parameter
The stored procedure looks like this:
CREATE ...

39. how to get insert sql in mysql shell or java library?    stackoverflow.com

my table is:

[tableAbc]
A B C
------------
1 a b
2 c e
3 e r
...
run:
show create table tableAbc;
to get the create table sql but how to get insert sql? like:
insert into `tableAbc` ('A','B','C') VALUES(1,'a','b');
...
any idea? (or ...

40. Database Custom Profiler FOr .Net or Java    stackoverflow.com

Microsoft provided us a way to create our own profiler by using Microsft.* namespaces. I can trace all queries going to any MS SQL instance. I need to do this on ...

41. Folder permissions based on users and groups    stackoverflow.com

Hey Im working on a folder tree and need to be able to limit the visibility of certain folder based on the user and the group they belong to. I already ...

42. Java and prepareStatement with MySQL    stackoverflow.com

I use Java to do some SQL queries. in general the queries that i want to perform are:

set @uid=?; set @friendsList=?; IF EXISTS(select 1 from fb_user_friends join fb_user on " +
  ...

43. Best SQL Option for Performance    stackoverflow.com

I currently need to execute a database query that involves data from three separate tables. (bases,member,sell_transaction) The bases table looks like the following

base_id(PK)    name    state

The member table looks like the following

id(PK)    last_name    username   email    first_name

The sell_transaction table has the ...

44. How to backup a Solr database?    stackoverflow.com

I wonder how to backup (dump) a Solr database? If it is only to copy some files, then please specify which files (filename, location etc). Thanks

45. Manually construct SQL with binary data in Java    stackoverflow.com

I have a small program that manually creates queries. In pseudo code, it's basically done like this string[] a = new string[x];
a[0] = "data 1";
a[1] = "data 2";
a[2] = "data 3";
string query ...

46. MySQL dump .sql script and import to an apache derby    stackoverflow.com

So presumably mysqldump can export to ansi compatible format so that you can import to other vendors' databases. However trying to import to an apache derby I face ...

47. sql time functions    stackoverflow.com

how can I do the analogous to SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40') in PostgreSQL, but in JDBC? thanks

48. multiple conditions in where clause    stackoverflow.com

i am using mysql. this query is working fine: SELECT * FROM tablename where Date >'20091109' and id='11'; but below this query does not return any thing. SELECT * FROM tablename where Date between ('20091109' ...

49. Is Java.sql's getRow() thread safe?    stackoverflow.com

Lets say I have a large number of threads inserting into a mysql database using Java.sql. After i perform an insert i would like to know the primary key of ...

50. Preventing SQL Injection In Ibatis    stackoverflow.com

Is there anything built into Ibatis that helps prevent SQL Injection attacks? I'm not looking for a list of ways outside of Ibatis to do this, and am just wondering if ...

51. Why is java.sql.DriverManager.getConnection(...) hanging?    stackoverflow.com

I am attempting to get a connection to my University's MySQL DB but the connection is hanging.

import java.sql.*;

public class ConnectToDB {
        public ...

52. errors while try to run executeQuery/prepared statements()    stackoverflow.com

SQL statement is not executedcom.mysql.jdbc.CommunicationsException: Communications link >failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.ConnectException MESSAGE: Connection ...

53. database questions in sql    stackoverflow.com

The following query is in SQL:

SELECT r.reservation_no, f.flight_no, r.departure_date,
       f.departure_time, f.duration
  FROM flights f, reservations r
 WHERE f.flight_no=r.flight_no AND r.customer_ssn="234567";
Print the results to ...

54. Java/Sql: return an average from a specific column problem    stackoverflow.com

I'm using embedded SQL with Java. I have a simple table where I want to return an average from the column that contains temperatures. I tried to use ResultSet but it ...

55. Null Pointer Exception throws in getConnection()    stackoverflow.com

I have the followiing situation: I have a java code which is connected with a database (MySQL). When i am running the java code from eclipse and taking data from database, ...

56. Does MySQL's JDBC driver have a facility for parsing SQL?    stackoverflow.com

I'm writing a Java tool to validate SQL statements. For SELECT queries, I can do it with Connection.prepareStatement and PreparedStatemet.getMetaData. No exceptions == good query. Unfourtunately it doesn't work with eg. ...

57. How can I backup a mysql database from Java?    stackoverflow.com

how to backup and restore my mysql database through java program

58. Using an external HD to write to and store a mysql Database    stackoverflow.com

I have set up mysql database to run with java and eclipse on my Mac, it is running great, but now I will generate aprox 4.3billion rows of data which will ...

59. How to design Database for this situation?    stackoverflow.com

I'm working a minimal game with Java and mysql. I encountered some difficulties with how to design my tables correctly. I need some advices: Let me be specific, I have 3 ...

60. PreparedStatement.addBatch in java has any restrictions?    stackoverflow.com

I'm trying to optimize the process of inserting a large number of results to a remote mySQL database. I'm using simple jdbc for that. Currently I'm replacing exiting statements with PreparedStatement ...

61. Java PreparedStatement SQL Syntax for LIKE    stackoverflow.com

I have a prepared statement as so:

private static final String SQL_LIST_GROUP = "SELECT * 
               ...

62. Mocking a MySQL server with Java    stackoverflow.com

Since I'm not really proficient with databases, some details may be irrlevant, but I'll include everything: As part of a project in my University, we're creating a website that uses JSP, servlets ...

63. Where do I sort?    stackoverflow.com

I have a database, which I query, and I'm unsure of where to perform the sorting of the results, so far I've have the following options.

  • At the MySQL query.
  • At list level(Using ...

64. Datatype for WHERE product_name IN (?)    stackoverflow.com

The title says it all. I'm using JDBC directly, no Hibernate or ORM layer, and I want to search a table for multiple product names at the same time via "SELECT ...

65. Populating a MySQL database with values    stackoverflow.com

I have a locally installed MySQL server on my laptop, and I want to use the information in it for a unit-test, so I want to create a script to generate ...

66. A problem connecting to a MySQL DB using JDBC    stackoverflow.com

Here's how I'm trying to connect:

try {
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   } catch (Exception e) {
      throw new DbConnectionException();
   }
   try ...

67. How to create your own callback for Ibatis SqlTemplateClientMap    stackoverflow.com

I'd like to know how to create my own callback for a SqlMapClientTemplate. Specifically so I can do batch calls.

68. Is there a workaround for JDBC w/liquibase and MySQL session variables & client side SQL instructions    stackoverflow.com

Slowly building a starter changeSet xml file for one of three of my employer's primary schema's. The only show stopper has been incorporating the sizable library of MySQL stored procedures ...

69. MYSQL syntax error using LIMIT in Java    stackoverflow.com

I'm running some simple MYSQL statements from within a Java application. I'm getting a syntax error on a statement that seems to run fine if I run it directly against the ...

70. Stumped SQL Exception for JDBC    stackoverflow.com

I'm trying all I can to get a JDBC to work, the only thing that is stumping me right now is this exception, which I have no idea about:

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have ...

71. Should the relationship between a Service and DAO be one to one or one to many?    stackoverflow.com

The code that sparked this question was a Service in my company's code base that contained four different DAO's. I didn't think much of this until I saw that this Service ...

72. What's wrong with my sql connection?    stackoverflow.com

I've created a web service to connect my android device to a mysql database. I made the web service in java using eclipse galileo. I know the web service is working ...

73. inner join prepared sql statement in java    stackoverflow.com

Good afternoon, i'm attempting to use a prepared statement to select a value from an SQL database. My input, is an ID in the table Notification. I get an ID, because of ...

74. delete sql not deleting    stackoverflow.com

I'm trying to delete an event from my table. However I can't seem to get it to work. My SQL statement is:

  public void deleteEvent(String eventName){
    String query ...

75. SQL exception: no value specified for parameter    stackoverflow.com

I am getting a SQL exception "no value for parameter 3", I print all the value on the console. Why does it throw an exception?

String update="select * from net_cr_dr where (soc_code=? ...

76. Show the ten first contacts that I have recieved message    stackoverflow.com

I want to create Sql statement that show the ten first contacts that I have recieved message from along with their latest sent message and time. The table columns is messageId, ...

77. JDBC SQL Connection    stackoverflow.com

I am trying to use JDBC to connect to a mysql database on our school's server. Here is my code:

    try
    {
    ...

78. SQL: ten first contacts that I have received message from or sent to along with their latest sent message and time    stackoverflow.com

I have a follow up to complicated mysql question that I recently asked: Show the ten first contacts that I have recieved message Now I know that it is missing something, ...

79. Best practice for multithreaded applications that talk to a sql database    stackoverflow.com

I have 20 factory machines all processing tasks. I have a database adapter that talks to a MYSQL database that the machines store all their info in. Is it safe to ...

80. Matcher.quoteReplacement versus preparedstatement    stackoverflow.com

In my project I have to create insert statements based on the tables passed. So I have two options 1)Write preparedstatement and run it in batch 2)Create insert into table values(..),(..),(..) I want to ...

81. How to know if an sql statement executed in java?    stackoverflow.com

I want to know if this delete statement has actually deleted something. The code below always execute the else. Whether it has deleted something or not. What's the proper way ...

82. Can't create SQL Statement - Java    stackoverflow.com

Well writing a login checker for a game, and switching from C# to java. Problem is I am using older code as an exmaple but keep running into this problem with ...

83. Java-Compare data from textbox to sql record    stackoverflow.com

Pretty much writing a launcher for a game and I need to take text from the Username text box, and a password textbox and then fetch the data from mysql server. ...

84. Java reset sql timeout    stackoverflow.com

I just want to test how to implement a timeout reset to a mysql server caused by an internet connection timeout. Therefore I have this little bit of code.

public static void ...

85. Java Sanitize Input for Database without PreparedStatement    stackoverflow.com

I know I've read the easy way of sanitizing user input into a database with Java is using PreparedStatement. But I was wondering if there was another way to sanitize user ...

86. Difference between java.sql and mysql.jdbc    stackoverflow.com

I've only learned Java last quarter of 2010. I can say the knowledge I gained as of now are not enough and there's a lot of improvement. I still do studying ...

87. how to monitor database transaction?    stackoverflow.com

I have written a webapplication for payroll system which can do (insert,update,delete) to mysql database. I want to know how many transaction happened in mysql database ?
how many transaction happened ...

88. How to retreive the password from a java.sql.Connection object    stackoverflow.com

I'm looking for a way to get the password from a java.sql.Connection object. I know there's a getUserName() method in the DatabaseMetaData object, but unfortunately no corresponding getPassword() method. ...

89. Netbeans J2EE SQL Driver not found    stackoverflow.com

Hey I made an EJB program and I created entity classes form my SQL database. Everything worked fine and it can connect to my database, but I get this error now ...

90. Generating a dymamic sql SELECT statement    stackoverflow.com

Hi all I'm having some small trouble trying to dynamicall generate an SQL SELECT statement generated from an entry from a webpage. Basically i have a small search engine in the website, it ...

91. Is it possible create new account in mysql from java?    stackoverflow.com

I need use sql without working with mysql. Just from java create account, databases, export and import databases. Its possible? Or I shoult prefer XML for it?

92. Mahout/Hadoop: SQL to SequenceFile    stackoverflow.com

I am starting to use Mahout for clustering, but I am having a hard time trying to convert a sql(mysql) dump to a mahout-compatible SequenceFile. I am using the code above. ...

93. Can MySQL stored procedures be used for anything Java is used for?    stackoverflow.com

i.e, can we just use stored procedures for everything? In a web-site backed by a DB that is.

94. java.lang.IncompatibleClassChangeError: Found class com.mysql.jdbc.Statement, but interface was expected    stackoverflow.com

when this exception come for SQL

java.lang.IncompatibleClassChangeError: Found class com.mysql.jdbc.Statement, but interface was expected
Can you please explain ? does it come due to mysql jar changes to next version ? ...

95. mySQL syntax error    stackoverflow.com

I have method:

@Override
public Group getGroupByStudentId(Long studentId) throws SQLException {
  // TODO Auto-generated method stub
  Group gr = null;

  String query = "SELECT `group`.idgroup,
      ...

96. Java PreparedStatement complaining about SQL syntax on execute()    stackoverflow.com

This is driving me nuts... What am I doing wrong here?

ArrayList<String> toAdd = new ArrayList<String>();
toAdd.add("password");
try{
    PreparedStatement pStmt = conn.prepareStatement("ALTER TABLE testTable ADD ? varchar(100)");
     ...

97. Can not issue data manipulation statements with executeQuery()    stackoverflow.com

I use com.mysql.jdbc.Driver I need insert and get id. My query:

INSERT INTO Sessions(id_user) VALUES(1);
SELECT LAST_INSERT_ID() FROM Sessions LIMIT 1;
error -
Can not issue data manipulation statements with executeQuery()
How insert and ...

98. Parsing and Inserting 10 million records into SQL    stackoverflow.com

So I have ~10 million records in an excel file that have to be parsed out in a specific way (I can't just convert to CSV and insert it like that) ...

99. Error in Code: java.sql.SQLException: No suitable driver found for TEST/ANKUR    stackoverflow.com

package javaapplication1;
import java.sql.*;
public class JavaApplication1{
  public static void main(String[] args) {
  System.out.println("MySQL Connect Example.");
  Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/TEST/ANKUR1";
  String dbName = "jdbctutorial";
 ...

100. When is a database called as an Embedded database?    stackoverflow.com

Does the term 'embedded database' carry different meaning from 'database'?