Tag: mysql

如何将java日期类型存储到mysql日期类型?

如何将java日期类型存储到mysql日期类型?

使用JDBC迭代大表的最快方法

我正在尝试创建一个java程序来清理和合并我的表中的行。 该表很大,大约500k行,我目前的解决方案运行速度非常慢。 我想要做的第一件事就是获取一个表示我表中所有行的对象的内存数组。 这是我正在做的事情: 一次选择1000行的增量 使用JDBC在以下SQL查询上获取结果集SELECT * FROM TABLE WHERE ID> 0 AND ID <1000 将结果数据添加到内存数组中 继续查询最多500,000,增量为1000,每次添加结果。 这已经很久了。 实际上它甚至没有超过从1000到2000的第二个增量。查询需要永远完成(尽管当我直接通过MySQL浏览器运行相同的东西时它速度相当快)。 我已经有一段时间了,因为我直接使用了JDBC。 有更快的替代方案吗?

使用Spring Hibernate的Google Appengine Cloud SQL问题

我在Amazon EC2上使用MySQL运行Spring Hibernate Application。 我正在考虑将我的应用程序移植到Google App Engine,因为Google现在支持使用Google Can SQL的MySQL。 因此,将我现有的应用程序配置为Google App Engine Web应用程序,然后编译代码而不会出现任何错误。 我没有更改任何内容到我现有的应用程序,它编译并创建了所需的表,服务器已成功启动。 但是,当运行通过hibernate访问数据库的应用程序时,我收到以下错误。 org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371) at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy30.findById(Unknown Source) at com.openentry.catgen.services.impl.WebsiteServiceImpl.getMasterDomain(WebsiteServiceImpl.java:99) 我正在为我的实体类使用注释。 有什么我需要改变的吗? 下面是我的applicationContext.xml ${hibernate.dialect} ${hibernate.show_sql} ${hibernate.format_sql} ${hibernate.generate_statistics} ${hibernate.connection.useUnicode} […]

PreparedStatement抛出语法错误

我正在使用PreparedStatements准备一个查询,当我用条件参数硬编码查询时它运行正常。 如果参数是从setString()方法传递的,则抛出错误。 com.mysql.jdbc.JDBC4PreparedStatement@2cf63e26: select * from linkedin_page_mess ages where company_id = ‘2414183’ com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘?’ at line 1 在错误日志中,我的查询上面看起来很好。 public JSONObject getLinkedInMessages(String compId) { linlogger.log(Level.INFO, “Called getLinkedInMessages method”); Connection conn = […]

SimpleDateFormatter.parse以不同于指定的格式提供输出

我需要获取UNIX时间戳(String),将其转换为特定格式的日期,并将其存储在DATETIME列中的MySQL DB中。 这是我的一段代码(简化): String ep =”a1527069600″; Long epoch = Long.parseLong(ep.substring(1, ep.length())); Date dt = new Date(epoch*1000L); SimpleDateFormat sdf = new SimpleDateFormat(“dd/MM/yyyy hh:mm:ss a”); a”); sdf.setTimeZone(TimeZone.getTimeZone(“Asia/Calcutta”)); System.out.println(“SDF.Format – “+sdf.format(dt)); System.out.println(“SDF.parse – “+sdf.parse(sdf.format(dt))); 控制台输出: SDF.Format – 23/05/2018 03:30:00 PM SDF.parse – Wed May 23 15:30:00 IST 2018 当我尝试在MySQL DB中推送此值时,它会抛出Invalid DateError。 只是混淆了为什么sdf.format和sdf.parse以不同的格式显示时间戳。

调用一个mysql函数在hibernate中返回varchar

我试图在hibernate中使用mysql find_in_set字符串函数但不幸的是我无法使用它甚至尝试通过创建这些寄存器函数 registerFunction(“findInSet”,newSQLFunctionTemplate(Hibernate.STRING,”FIND_IN_SET(?1,?2)”)); registerFunction(“findInSet”,newSQLFunctionTemplate(Hibernate.INTEGER,”FIND_IN_SET(?1,?2)”)); registerFunction(“findInSet”,new StandardSQLFunction(“find_in_set”, Hibernate.INTEGER)); 使用mysqldialect但没有人工作..任何人请告诉我如何在hibernate中使用mysql字符串函数。 或对上述寄存器function的任何更改。 提前致谢, 最诚挚的问候,拉贾。

连接池中的最佳连接数

目前我们正在使用4个带有8GB RAM的cpu windows box,MySQL 5.x安装在同一个盒子上。 我们正在为我们的应用程序使用Weblogic应用程序服务器 我们针对我们的应用程序定位了200个并发用户(显然不适用于相同的模块/屏幕)。 那么我们应该在连接池中配置什么是最佳连接数(最小和最大数量)(我们使用的是weblogic AS’连接池机制)?

优化JDBC中的数据调用到JTable上

目前我在MySQL服务器上有数据,我通过JDBC将数据调用到JTable。 但是有1369行,似乎它有太多的数据要加载。 通常需要5分钟才能加载。 有没有优化过程? 这是我的代码(我提前为一个混乱的代码道歉): public class DataTable { private String databaseName = “*****”; private String tableName = “******”; public void showDatabase(){ Connection conn = null; DatabaseMetaData meta = null; Statement stmt = null; ResultSet rs = null; int k = 0; try{ Class.forName(“com.mysql.jdbc.Driver”).newInstance(); String connectionUrl = “jdbc:mysql://localhost:3306/” + databaseName; String connectionUser = “*****”; String […]

根据android studio编译器,数据库表不存在

我收到此错误: android.database.sqlite.SQLiteException:没有这样的表:设置(代码1):,同时编译:SELECT * FROM setting 但我在DatabaseHandler文件中创建了表: public class DatabaseHandler extends SQLiteOpenHelper { // Database Version private static final int DATABASE_VERSION = 1; // Database Name private static final String DATABASE_NAME = “database.db”; //table name private static final String TABLE_DETAILS = “details”; private static final String TABLE_FOOD = “food”; private static final String TABLE_OLDDETAILS = “oldDetails”; […]

无法从Java执行MySQL存储过程

我正在从运行在tomcat中的Web应用程序连接到Linux机器上运行的MySQL(5.08)数据库。 我尝试执行存储过程时收到以下exception: com.hp.hpl.chaos.web.exception.DBException: getNextValue for operatorinstance[Additional Information from SQL Exception][SQLErrorCode: 0 SQLState: S1000 at com.hp.hpl.chaos.web.util.SQLUtil.getNextValue(SQLUtil.java:207) ………….. Caused by: java.sql.SQLException: User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted, configure connection with “noAccessToProcedureBodies=true” to have driver generate parameters that represent INOUT strings irregardless of actual […]