jdbc

Can't make JDBC connection to MySQL (using Java, IntelliJ, and Linux)

I am having issues trying to get a database connection using the code below: try { Class.forName("com.mysql.jdbc.Driver"); Properties p = new Properties(); p.put("user", user_name); p.put("password", password); connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/jsp_test", p); }...

SQL Server Windows Authentication using a Service

I am running a Java Application as a Service in Windows that's using JDBC to connect to SQL Server. This application is started as a different user than the one logged into the Machine. My question is will the JDBC Driver use the user assigned to start the service to authenticate against or the logged in user (which there might not be on...

Spring Jdbc query execution

Does anyone know how what Spring Jdbc template method I could use to execute this 'upsert' or an alternative approach that would also perform the operations in one database call? UPDATE jasper_report SET Uri = 'update' WHERE ReportId = 99; IF @@ROWCOUNT = 0 AND Exists(Select 1 FROM report Where Id = 99) BEGIN INSERT INTO jasper_r...

Using a java class to create a database

Hi, I'm working in an application that uses servlets and mysql. I'd like to create a .jar file able to create the database that the application will be using. This will only be done once, in order to create the db. I've no problem in getting to access to a database, doing something like this: Class.forName("com.mysql.jdbc.Driver").ne...

What is a good tool for the investigation of Database Connection usage in Java?

What is a good tool for the investigation of Database Connection usage in Java? A developer is supporting a complex Java program which is ocassionally exhausting the number of Database connections available. Since the problem is sporadic it would be useful to know which thread has opened multiple connections to the database to focus the...

SQL Server Exception: "The column name xxx is not valid" when using JDBC

I'm getting a strange error from the SQL Server JDBC driver. It is telling me that a column name is invalid even though the column is present, correctly named and the same query works fine when executed in SqlServer Management Studio. The error is: Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The column name MarginCall i...

Java: Trouble connecting to MySQL

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 Connection getDBConnection() throws SQLException, InstantiationException, IllegalAcces...

Java: ResultSet exception - before start of result set

I'm having trouble getting data from a ResultSet object. Here is my code: String sql = "SELECT type FROM node WHERE nid = ?"; PreparedStatement prep = conn.prepareStatement(sql); int meetNID = Integer.parseInt(node.get(BoutField.field_meet_nid)); prep.setInt(1, meetNID); ResultSet result = prep.executeQuery(); r...

Problem with not closing db connection while debugging?

I have a Java app that opens a connection to a database at the beginning, and closes it at the end. However, the program doesn't always finish, because an exception is thrown or I am debugging it and stop it halfway through. Will this cause open connections to pile up and slow the database, or will it be cleaned up automatically? ...

Java: DB Communications Link Failure

My program that connects to a MySQL database was working fine. Then, without changing any code used to set up the connection, I get this exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any ...

mysql: find rows which have a field that is a substring of "string"

is there a way to write an sql query that finds all rows where the field value is a substring of a given string. Example: table names Name | Nickname rohit iamrohitbanga banga rohitnick sinan unur query should be something like select * from names where Name is a substring of "who is rohit...

Jetty mysql connection-pool configuration error: javax.naming.NameNotFoundException; remaining name 'env/jdbc/---(mysql 5.0+jetty 7.0.1)

My configuration files project/WEB-INF/web.xml: <resource-ref> <description>ConnectionPool DataSource Reference</description> <res-ref-name>jdbc/mysql</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> project/WEB-INF/jetty-env.xml: <New id="mysql" class="org.eclip...

Why would number columns' scale and/or precision differ in JDBC from Oracle 10 to 11?

For our database development we have on one hand a full schema DDL script, for scratch installs, and on the other a set of sequential "delta" scripts, for upgrades (each script is recorded as executed or not in a special database table). To test this we have an ant target that install an older version, upgrades it and compares the schem...

SQL Server JDBC returns many result set when a stored procedure invoked.

By default SQL Server JDBC driver returns result set of all SELECT query executed in a stored procedure. I have to call CallableStatement.getMoreResults() and close all of them. I do not want any result set as return value when executing SQL Server stored procedurel; are there any ways to prevent returning result set when executing SQL S...

Export oracle table data as sql Insert-String

Hi Guys, this is me Francisco that wrote the first question click-here , but now I've an account. I'll try to explain it. For a Job I need a .txt file that contains the SQl string inserts from an Oracle Table. I can't use a Software like toad because I need to do it with Java Code. I'm not trying to get the inserts's logging , I need a ...

Select BigSerial Column Data from Informix Table

The scenario is like that. User will specify a database table name and the system will retrieve and display all the data stored in the specified informix database table. Class.forName("com.informix.jdbc.IfxDriver"); Connection conn = DriverManager.getConnection(connUrl) Statement stmt = conn.createStatement(); ResultSet rs = stmt.exec...

Java JDBC clearBatch() and heap memory

I've noticed the following behavior. I have a file that is about 3MB containing several thousand rows. In the rows I split and create prepared statement (about 250 000 statements). What I do is: preparedStatement addBatch do for every 200 rows { executeBatch clearBatch(). } at the end commit() The memory usage will increase to ...

using Spring JdbcTemplate

if i create a new instance of JdbcTemplate like so; JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource()); by passing the datasource as a param (the datasource retrieves a connection from server connection pool) am i required to close the connection when im finished with it? In other words, if i have a pool of connections will...

Database to GlazedList/Jtable and then edit the database through the GlazedList/JTable

I am able to break this problem down into two questions: What is the best way to put the contents of a database (MS-Access) into a GlazedList/JTable? How do I make sure any changes made to the GlazedList/JTable are reflected on the database (MS-Access)? Here are the things I know: I know how to retrieve/manipulate the information f...

Connect to an Oracle cluster in Java

We have a pair of Oracle servers which are set up as nodes in a cluster (apologies if my terminology is way off). In my tnsnames.ora file, we have an entry that looks like EXAMPLE.GOV = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 1.2.3.4)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 1.2.3.5)(PORT = 1521)) (LOAD_...