天道酬勤,学无止境

jdbc

Using a mysql-variable in java (for a ranking-query)

I'd like to create a ranking in a MySQL-Table for Users, sorted by their score. I already found a nice Query for that, but this Query is only working with phpmyadmin, not in java... I got the following MySQL-Query which works well in phpmyadmin to create a Ranking: SET @r=0; UPDATE `hg_stats` SET `stats_rank`= @r:= (@r+1) ORDER BY `stats_score` DESC; In Java: try { preparedStatement = connection.prepareStatement("SET @r=0; UPDATE `hg_stats` SET `stats_rank`= @r:= (@r+1) ORDER BY `stats_score` DESC;"); preparedStatement.executeQuery(); } catch (SQLException e) { e.printStackTrace(); } I am

2021-10-26 01:24:00    分类:问答    java   mysql   sql   jdbc   ranking

为什么 Kafka jdbc 将插入数据作为 BLOB 而不是 varchar 连接(Why Kafka jdbc connect insert data as BLOB instead of varchar)

问题 我正在使用 Java 生产者在我的 Kafka 主题顶部插入数据。 然后我使用 Kafka jdbc connect 将数据插入到我的 Oracle 表中。 下面是我的生产者代码。 package producer.serialized.avro; import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericRecord; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.clients.producer.ProducerRecord; import java.util.Properties; public class Sender4 { public static void main(String[] args) { String flightSchema = "{\"type\":\"record\"," + "\"name\":\"Flight\"," + "\"fields\":[{\

2021-10-26 00:50:16    分类:技术分享    oracle   jdbc   apache-kafka   apache-kafka-connect   confluent-platform

Spring boot manually commit transaction

In my Spring boot app I'm deleting and inserting a large amount of data into my MySQL db in a single transaction. Ideally, I want to only commit the results to my database at the end, so all or nothing. I'm running into issues where my deletions will be committed before my insertions, so during that period any calls to the db will return no data (not good). Is there a way to manually commit transaction? My main logic is: @Transactional public void saveParents(List<Parent> parents) { parentRepo.deleteAllInBatch(); parentRepo.resetAutoIncrement(); //I'm setting the id manually before hand String

2021-10-25 23:07:54    分类:问答    spring-boot   jpa   jdbc

Placing an image in an object, sending the object over rpc and then using hibernate

I am using gwt rpc and hibernate on the back end. I have an object in which one of the field is an image. I have to place the image in the object, send the file over rpc and saving it back to database using hibernate. Does anyone of you have an idea about this??

2021-10-25 22:01:20    分类:问答    database   hibernate   gwt   jdbc   binaryfiles

glassfish error

SEVERE: javax.naming.NamingException: Lookup failed for 'jdbc:mysql://localhost:3306/sample ' in SerialContext [Root exception is javax.naming.NameNotFoundException: jdbc:mysql:] what to do to rectify? i am running jsp code in netbeans and i am using mysql as dbms

2021-10-25 21:48:56    分类:问答    java   jsp   jdbc

从 JDBC 驱动程序访问 sqlite db(Accessing sqlite db from JDBC driver)

问题 我正在尝试将 sqlite db 集成到我的基于 tomcat spring 的 Web 应用程序中。 我在 DAO 类中使用 JDBC 驱动程序获取到 db 的连接,如下所示。 Class.forName("org.sqlite.JDBC"); con = DriverManager.getConnection("jdbc:sqlite:mydb.db"); 但是我无法连接到我的数据库。 这是我放置 db 和 DAO 类的方式。 DAO CLASS = src->main->java->mypackage->DAO.java 数据库文件 = src->main->resources->mypackage->mydb.db 部署时,类文件和 .db 文件都位于 tomcat 中的同一位置。 但是,如果我给 mydb.db 提供绝对路径,它就可以完美运行。 我在这里做错了什么,非常感谢任何帮助。 编辑 1:我得到表未找到异常。 当我提供完整路径时,它会更新数据库 java.sql.SQLException: no such table: product at org.sqlite.NativeDB.throwex(NativeDB.java:210) at org.sqlite.NativeDB._exec(Native Method) at org.sqlite.Stmt

2021-10-25 21:11:15    分类:技术分享    java   spring   sqlite   tomcat   jdbc

jdbc mysql 与远程数据库的通信链接失败 [重复](jdbc mysql communications link failure to remote database [duplicate])

问题 这个问题在这里已经有了答案: 将 Java 连接到 MySQL 数据库(14 个回答) 4年前关闭。 我正在尝试在我的java程序中使用jdbc连接到mysql数据库。 我正在使用 RHEL 6 机器连接到 mysql 数据库。 我已经在这台机器上打开了端口 3306,如果我打开了, mysql -u root -p mysql 数据库连接。 如果我这样做, mysql -h servername.edu -u root -p mysql 数据库连接。 从我的java程序, String url = "jdbc:mysql://localhost:3306/"; 作品。 现在,如果我将 localhost 更改为 servername,则不起作用。 String url = "jdbc:mysql://server.com:3306/"; 我得到的错误是, com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure to remote databse 在发布问题之前,我从这里对这个异常做了一些研究。 我已正确设置my.cnf文件,但在该文件中没有发现问题。 我在这里缺少什么? 对服务器的正常ping能正常工作。 回答1 CommunicationsException

2021-10-25 21:09:45    分类:技术分享    java   mysql   database   jdbc

Java JDBC SQL Exception

I am currently working on a script in Java to import a bunch of books from a lengthy plain text file to a database. I have all of the books parsed into book objects and am trying to write them to the database. However, I get a missing comma exception "ORA-00917: missing comma" on the Following String: INSERT INTO THE_TABLE VALUES( 'Yes' , '50388,50389' , 'Humanities and Performing Arts' , 'Required' , 'Ember, Carol & Ember, Melvin' , 'Human Culture' , '2nd' , '2012' , 'Pearson' , 'This is for CRN's 4879 & 2486' , '9780205251438' , '50' , 'null' , 'null' , 'null' , 'Spring 2013' , 'ROTN 4270'

2021-10-25 21:01:49    分类:问答    java   sql   jdbc

ORA-00942: Spring Boot 中的 Spring JDBC 模板不存在表或视图(ORA-00942: table or view does not exist with Spring JDBC Template in Spring Boot)

问题 我收到一个奇怪的ORA-00942: table or view does not exist尝试通过 Spring JDBC 模板执行数据库代码时出现异常: 2019-12-26 22:01:36.863[0;39m [31mERROR[0;39m [35m12232[0;39m [2m---[0;39m [2m[ctor-http-nio-3][0;39m [36ma.w.r.e.AbstractErrorWebExceptionHandler[0;39m [2m:[0;39m [ca8305eb] 500 Server Error for HTTP GET "/exs/acs/accounts-links?limit=20&q=632626&showActive=false&systemName=IMMS" org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [select a.FACCIN, a.FACCKEY, a.FACCSNAME, b.LNKSYSTEM, b.LNKLOANKEY, a.FACCSTATUS, a.FACCCOND from BNYMACS.ACCOUNT a left outer join BNYMACS

2021-10-25 20:56:39    分类:技术分享    oracle   jdbc   spring-data   spring-jdbc   ojdbc

Error displaying the autonumber field from a ResultSet

The movie which is inputted is successfully saved to moviesTbl table but then when I try to display the autonumber field 'MovieID' I retrieve errors. public void updateMovies(String update, String title, java.sql.Date releaseDate, String genre) throws SQLException { Connection connection = dc.DatabaseConnection(); PreparedStatement statement = connection.prepareStatement(update); //the insert statement is prepared statement.setString(1, title); //each attribute is set individually statement.setDate(2, releaseDate); statement.setString(3, genre); statement.executeUpdate(); statement.close()

2021-10-25 19:41:14    分类:问答    java   ms-access   jdbc   resultset