jdbc

problem in jdbc preparestatement

i am geting error when i try to use following,why is it so? ResultSet findByUsername(String tablename,String field,String value) { pStmt = cn.prepareStatement("SELECT * FROM" + tablename +" WHERE ? = ? "); pStmt.setString(1,field); pStmt.setString(2,value); return(pStmt.executeQuery()); } also i tried following , bu...

Batch insert using groovy Sql?

How can you do a batch insert using groovy Sql while simulating prepared statements? All the examples I've found are similar to the following and don't use prepared statements. withBatch { stmt -> stmt.addBatch("insert into table (field1,field2) values('value1','value2')") stmt.addBatch("insert into table (field1,field2) values('value3...

Passing DataSource object from a servlet to a JavaBean

I like the ease of using @Resource annotation to get a DataSource, but as far as I know, it's not possible to use it in a regular JavaBean. Would it be considered a bad practice if I pass the DataSource object from a servlet to a bean along with the other data to avoid having that lookup code in the bean? ...

SQL java get value assigned to auto increment primary key

I have a primary key auto increment attribute in my table. I want to know the value assigned to it for a row that is inserted using statement.executeUpdate(). How to achieve this in the best possible manner? ...

How to connect to SQL Server using activerecord, JDBC, JTDS and Integrated Security

As per the above, I've tried: establish_connection(:adapter => "jdbcmssql", :url => "jdbc:jtds:sqlserver://myserver:1433/mydatabase;domain='mynetwork';", :username => 'user', :password=>'pass' ) establish_connection(:adapter => "jdbcmssql", :url => 'jdbc:jtds:sqlserver://myserver:1433/mydatabase;domain="mynetwork";user="mynetwork\user...

sql jdbc getgeneratedkeys returns column "id" not found, column type unknown

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 by sqlQuery varchar(30) timestamp // has a default value. but i am explicit assigning it using CURRENT_TIMESTAMP varchar(300) varchar(300) varcha...

Open JdbcTemplate connection in read only mode (Spring framework)?

Hi, is it possible to open a JdbcTemplate connection in read only mode, so that I can't perform any changes to the underlying data source? ...

Cannot use a Like query in a JDBC prepared statement?

OK, first the query code and query: ps = conn.prepareStatement("select instance_id, ? from eam_measurement where resource_id in (select RESOURCE_ID from eam_res_grp_res_map where resource_group_id = ?) and DSN like '?' order by 2"); ps.setString(1,"SUBSTR(DSN,27,16)"); ps.setInt(2,defaultWasGroup); ps.setString(3,"%Module=jvmRuntimeModu...

PreparedStatement and setTimestamp in oracle jdbc

Hi everyone, I am using PreparedStatement with Timestamp in where clause: PreparedStatement s=c.prepareStatement("select value,utctimestamp from t where utctimestamp>=? and utctimestamp<?"); s.setTimestamp(1, new Timestamp(1273017600000L)); //2010-05-05 00:00 GMT s.setTimestamp(2, new Timestamp(1273104000000L)); //2010-05-06 00:00...

Is jdbc or ldap faster for basic read operations?

I have a set of user data which I am try to access. Due to the way our company's employee data is set up, the information is available both through LDAP and through a table in our DB. I was curious, for standard read operations which would generally be a higher performance query? ...

Difference between library and native library

Could anyone tell me the difference between library and native library in terms of java? I found the word "native library" in the following line: Type 1 - drivers that implement the JDBC API as a mapping to another data access API, such as ODBC. Drivers of this type are generally dependent on a native library, which limits th...

What is the best approach using JDBC for parameterizing an IN clause?

Say that I have a query of the form SELECT * FROM MYTABLE WHERE MYCOL in (?) And I want to parameterize the arguments to in. Is there a straightforward way to do this in Java with JDBC, in a way that could work on multiple databases without modifying the SQL itself? The closest question I've found had to do with C#, I'm wondering i...

Hibernate is persisting entity during flush when the entity has not changed

I'm having a problem where the entity manger is persisting an entity that I don't think has changed during the flush. I know the following code is the problem because if I comment it out the entity doesn't persist. In this code all I'm doing is loading the entity and calling some getters. Query qry = em.createNamedQuery("Clients.findBy...

SQLiteJDBC giving org.sqlite.MetaData.getImportedKeys not yet implemented error with Hibernate

Hi all, SQLiteJDBC was giving me the following exception when used with hibernate's "hbm2ddl.auto = update" setting: org.sqlite.MetaData.getImportedKeys not yet implemented Any solutions? I found one below, and am posting it here for my future reference, but anyone else have any better ideas? ...

Failed to obtain JDBC Driver for MySQL under Tomcat environment

Hi all: I've been trying to obtain the Driver class for JDBC connection to MySQL. The workstation is running on Linux, Fedora 10. I have manually set up the classpath variable for Java by CLI like this: bash-3.2$ echo $CLASSPATH /home/cmao/public_html/jsp/mysql-connector-java-5.1.12-bin.jar This shows that I've added the lastest mysq...

Connection drop problem with Hibernate-mysql-c3p0

hi all, This is an issue which I have seen all across the web. I will bring it up again as till now I don't have a fix for the same. I am using hibernate 3. mysql 5 and latest c3p0 jar. I am getting a broken pipe exception. Following is my hibernate.cfg file. com.mysql.jdbc.Driver ...

How to make a thread try to reconnect to the Database x times using JDBCTemplate

Hi, I have a single thread trying to connect to a database using JDBCTemplate as follows: JDBCTemplate jdbcTemplate = new JdbcTemplate(dataSource); try{ jdbcTemplate.execute(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection con) throws SQLException { ...

Service bus Vs direct database access

What are the advantages of using an ESB instead of directly accessing a database (via Hibernate or JDBC). I know you can reuse the messages on the bus, but could you not just package up your database access code into a jar and distribute it to the different systems that need access (Assuming all the accessing systems support Java)? ...

Indexing File Names To a Database

I have a folder with more than 2000 files and I need to index their file names on a database(MySQL) using Java, but how could I do this? PS: The MySQL connection part I already know. ...

Efficiently fill resultset in object model

Hi, I have an object model whose structure is Dashboard  List of panels     List of containers       List of widgets If i get whole dashboard, with panels + containers + widgets, from Database then multiple I/O requires I want to get it in one I/O .For this i prepared a query which gives me this resultset. DA...