Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all 884 articles
Browse latest View live

using jdbc and mySQL without throwing exceptions (1 reply)

$
0
0
Hi,

i intend to use JDBC in order to connect to a mySQL database. Basically I got JDBC to work in order to read data out of the database and the use it!

Now i wanted to use this quite simple functionality in a different framework which apparently doesn't allow the classes to throw exceptions!

Therefore my question is whether it is possbile to use JDBC and mySQL without throwing or exceptions or is that per definition necessary?

Does somebody has experience with such a problem?

greetz

quoted identifiers during table creation (1 reply)

$
0
0
When I give quoted identifiers in a PreparedStatement, I get the following error. I would really appreciate any input/advice. If this is not the right way, kindly recommend me an alternative to do this.

Error message: 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 ''%col_string' VARCHAR(254))' at line 1

// Create table called my_table
String sql2 = "CREATE TEMPORARY TABLE my_table('%col_string' VARCHAR(254))";
stmt.executeUpdate(sql2);
stmt.close();
System.out.println(sql2);

String sql = "CREATE TEMPORARY TABLE dataset_temp(";
for (int k = 0; k<mNumCols; k++) {
sql += "? varchar(20)";
if (k < mNumCols-1) sql += ",";
}
sql += ")";

PreparedStatement pstmt = connect.prepareStatement(sql);
for (int k = 0; k < mNumCols; k++) {
String headerName = sheet.getCell(k,0).getContents();
if(headerName == null || headerName.length() == 0) {
headerName = "null" + k;
}
pstmt.setString(k+1, headerName);
System.out.println(headerName);
}
System.out.println(sql);
pstmt.executeUpdate();
pstmt.close();
connect.close();

Browse Large Table in Java? (1 reply)

$
0
0
Hi All,

I am writing a Java program (AWT or Swing as interface) to show content of a large table in my mysql database on screen (let's say inside a JList). There is no way I can read the entire table into a ResultSet and it doesn't make sense to go and fetch record by record. What do you suggest the best way showing the content and let user browse the data by pushing PageUp/PageDown?


Thanks in Advance,

Homer

Forward Only navigation in large tables (no replies)

$
0
0
Hi,

I need to retrieve several large (>300k rows) results from 100 tables.
Each of these tables has 101 columns.

Does any of you have an idea about the best strategy ?

I am currently planning to test the two following ones.

1) Retrieving by block (500 rows at a time for instance)
1a) using WHERE clauses
1b) using LIMIT xxx OFFSET yyy clauses

2) Line by line with
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);

As indicated in the documentation of MySQL/JDBC

Any thought ?

Regards

A strange problem while use PreparedStatement in mysql jdbc driver (1 reply)

$
0
0
code is on list:
String sql = "select stockid, sum(stocknumber) total from fundstockdetail where quarter=? group by stockid ";
st =con.prepareStatement(sql);
st.setInt(1,quarter);
ResultSet rs=st.executeQuery(sql);

but executeQuery report exception:

com.mysql.jdbc.exceptions.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 '? group by stockid' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3099)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1169)

but "insert into fundstockdetail values(?,?,?,?,?,?,?,?)" is good running,
how can resolve this problem,and what's the reason?

I am use mysql-5.0.4,the jdbc driver is mysql-connector-java-5.0.4-bin.jar,
I try to change the jdbc driver version,but the problem still exists.

Caching of "SHOW CREATE PROCEDURE" (1 reply)

$
0
0
It seems that the connector send "SHOW CREATE PROCEDURE" before _all_ calls to procedures. I don't know the impact of this on the server but it seems very unnecessary to do this _all_ the time.

Is there an option to cache this on the client? Our procedure signatures can't change without the client being changed anyway so we could cache those calls forever.

Thanks.

error with function (1 reply)

$
0
0
I have made a function nextval to work like the the oracle nextval. I call this from ibatis. this intermittently gives me the following error
Caused by: java.sql.SQLException: Column 'nextval('s_person_id')' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1145)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2814)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:237)
at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.ibatis.common.jdbc.logging.ResultSetLogProxy.invoke(ResultSetLogProxy.java:47)
at $Proxy3.getInt(Unknown Source)
at com.ibatis.sqlmap.engine.type.IntegerTypeHandler.getResult(IntegerTypeHandler.java:35)
at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMappingValue(BasicResultMap.java:611)
at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getResults(BasicResultMap.java:344)
at com.ibatis.sqlmap.engine.mapping.result.AutoResultMap.getResults(AutoResultMap.java:55)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:381)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:301)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:190)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)

ibatis version is ibatis 2.3.0 build# 677
mysql connector is
mysql-connector-java-5.1.12-bin.jar
I call the function as
select nextval('s_person_id');
is this a know issue with connector or am I getting something wrong.
any help is highly appreciated!
thanks!

Recommendations connecting to the database (no replies)

$
0
0
Hi!

I am going to use java and mysql for my application, but I'm not really sure of how to use jdbc for the best performance.

A short background to what the application will do: capture ip packages and insert extracted data into a database with up to 100 packets per second peak time. there might be the need of some ip -> int, mac -> long conversions when inserting..if that is more effective than storing just strings. Basically one package would consist of timestamp,ip,mac1,mac2.

So..I have been thinking, since I would use a consumer / producer pattern, with one queue, and only one thread doing database inserts I was thinking that no connection pooling would help..I would just open a connection once and keep it open, since i am capturing and inserting live. Also..since I would be using some conversions maybe stored procedures would be the best...and then just JDBC, and no extra layer above it.

Does it sound reasonable using JDBC (and mysql myisam) using stored procedures for this kind of application? Would it be better to use batch updates instead of stored procedures and take 1000 at a time or just do on the fly with stored procedures?

Thankful for all advices!

which my sql connector should be used for java tomcat 6.0.14 (1 reply)

$
0
0
my web site is running fine but not interacting with database so please any one suggest me which my sql connector should be used for java tomcat 6.0.14 (i m using private JVM)

How to Create Database with MySQL on an Application Designed in Java (no replies)

$
0
0
Hello There,

I have an application written in Java lang but database is MySQL. My challenge is to create database and import the data to SQL. Am using MS windows Vista and already have MySQL instance running, how do i achieve this please?

In addition, i have APACHE folder contains PHP files and previously designed for different application. WinLAMP used to manage, create and configure database for the previous design, absolutely worked fine previously though. Tried to login back to the application with my username and password i got msg

"Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\Apache2\htdocs\Stock Control PHP\DB.php on line 6
Error connecting to mysql"

Can someone help me out pls?

Unable to connect to MySQL database (no replies)

$
0
0
I installed MySql on Windows 7 and I put the Connector/J in the /lib/ext folder. I'm trying to connect to a database from Java, but I keep getting this error message:

"Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server."

This is my code:

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test",
"test_user", "password");
con.close();


How do I fix this?

mySQL Conncetion with JDBC in OpenOffice (Installproblem) (no replies)

$
0
0
Hello together,

I have no idea how to install the CONNECTOR/J in OpenOffice for accessing a mySQL DB in OO Base. I have have downloaded the .jar file. what do I have to do next?

Please give me a hint!

Regards, Kev

ON DUPLICATE KEY UPDATE statement not rewritten as multi-value insert in batch (no replies)

$
0
0
Hi.

According to the presentation at http://assets.en.oreilly.com/1/event/21/Connector_J%20Performance%20Gems%20Presentation.pdf, Connector/J 5.1.8 and later should rewrite ON DUPLICATE KEY UPDATE statements as multi-value inserts if rewriteBatchedStatements=true.

I'm using version 5.1.13, and have rewriteBatchedStatements=true, but I don't see that behaviour. I can see standard INSERTs (without ON DUPLICATE KEY UPDATE) being rewritten as multi-value inserts, and the driver does turn my batch into a multi-statement (multiple INSERTs separated by semi-colons), but not a multi-value INSERT.

My table is as follows (table and column names truncated to protect the innocent) :

CREATE TABLE `ca` (
  `Da` date NOT NULL,
  `Ev` smallint(6) NOT NULL,
  `At` smallint(6) NOT NULL,
  `To` int(11) DEFAULT NULL,
  `Co` bigint(20) DEFAULT NULL,
  UNIQUE KEY `Ca_UniqueValue` (`Da`,`Ev`,`At`,`To`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

The prepared statement I am executing in a batch as follows:

INSERT INTO catalog (Da, Ev, At, To, Co) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Count = Count + ?

Would you expect this batch of statements to be rewritten as a multi-value insert?

Thanks.

Neil.

Unable to connect to any hosts due to exception: Connection refused (no replies)

$
0
0
I have a JAVA application that I'm trying to deploy to a new server. The application works fine in my test environment but keeps producing "connection refused" exceptions in the new environment. An example of the exception is shown below. I checked MySQL connectivity by logging in at the command line and everything looks fine. I have a suspicion that it's something to do with either the MySQL configuration of the networking configuration but I'm not sure. Can anyone point me in the right direction?

DB ERROR: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1719)
at com.mysql.jdbc.Connection.<init>(Connection.java:432)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:400)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at importCasemgmt.main(importCasemgmt.java:80)

i am not able to connect java with mysql (1 reply)

$
0
0
Hi,
Sorry,I got your mail id from the Q/A Forum.I have my java application and try to connect with mysql database.But i can't able to get the output,i am getting the Exception error.I think i am not able to connect with the driver.My OS is Linux(Ubuntu).
-----------------------------------------
nikki@nikki-laptop:~$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9) (6b20-1.9-0ubuntu1)
OpenJDK Client VM (build 17.0-b16, mixed mode, sharing)

nikki@nikki-laptop:~$ echo $CLASSPATH
.:/usr/share/java/mysql.jar:/home/nikki/temp/src/jclass
-------------------------------------------------
My Java program is


import java.sql.*;
class Query1
{
public static void main(String args[])throws Exception
{
try
{ // the mysql driver string
Class.forName("com.mysql.jdbc.Driver").newInstance ();
// the mysql url = "jdbc:mysql://THE_HOST/THE_DATABASE";

//String url = "sun.jdbc.odbc.JdbcOdbcDriver";

String url ="jdbc:mysql://localhost/mylib_db";

Connection conn = DriverManager.getConnection(url,"nikki","dkm007");
Statement stmt = conn.createStatement();
//ResultSet rs;
ResultSet rs = stmt.executeQuery("select title from Book_dim where cost=435.89");
while (rs.next())
{
String titlename = rs.getString("title");
System.out.println(titlename + "\n");
}
conn.close();

}
catch(Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
--------------------------------------------
My output is
- - - - -
nikki@nikki-laptop:~/Documents/Chinu/mydbP$ javac Query1.java
nikki@nikki-laptop:~/Documents/Chinu/mydbP$ java Query1
Got an exception!
com.mysql.jdbc.Driver
--------------------------------------------------------------------------------------
I didn't added any driver...i don't know which Driver should i use .
If possible plz send me the reply.

Unable to connect eclipse with mysql 5.1.50 (1 reply)

$
0
0
AM a newbie tryin to connect eclipse to the mysql database.I have followed the steps as mentioned on wiki but get the following error when i test connection.unable to ping and in details the following is given.Some please tell me where i am goin wrong please.

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.net.FactoryURLClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:212)
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:73)
at org.eclipse.datatools.enablement.internal.mysql.connection.JDBCMySQLConnectionFactory.createConnection(JDBCMySQLConnectionFactory.java:28)
at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:358)
at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

How to create MYSQL db connection from Intuit webpage (no replies)

$
0
0
Hi, I have created a webpage in Intuit and now need to call a database table from MYSQL.

Looking for instructions on how to add the necessary java code into the Intuit webpage. Intuit does not provide this service/info.

Thanks in advance!

Joe

JDBC CallableStatement Registering Output Parameter of Type CURSOR (2 replies)

$
0
0
How to register the output parameter type CURSOR for a procedure call in JDBC?

Time Zones and JDBC (1 reply)

$
0
0
Hi,
I have a few questions regarding the exact way that Connector/J handles/retrieves/converts Time Zones.

Setup: I have a server on which both my MySQL server and JVM are running. My MySQL server's GLOBAL timezone is set to GMT+10:00, my system time is set to Australian/Eastern (normally GMT+10:00, but DST=GMT+11:00 from ~October-March).

I am writing a java application that works entirely in GMT+10:00, and which needs to collect dates stored in the MySQL database, all of which are stored in DATETIME fields.

I am trying to use ResultSet.getTimestamp(DATETIMEField,GMT+10Calendar) to retrieve the dates from the database and use them in the application. However, despite the fact that I am using useTimezones=true in the connection URL, all dates that fall within DST according to my SYSTEM TIME are displayed as 1 hour too early (08:00 when should display 9:00, using a SimpleDateFormat(java.sql.TimeStamp) configured to use GMT+10:00).

What I think is happening is this: MySQL is passing the date correctly to the JDBC as a String (or similarly static object) formatted as GMT+10:00. However JDBC is unable to work out (for whatever reason, I could easily have something set up incorrectly) what timezone this is supposed to be in, and so interprets it as being in SYSTEM TIME, meaning that the date stored is ONE HOUR TOO EARLY relative to UTC. When this intermediate date object is retrieved from the ResultSet as a java.sql.TimeStamp using ResultSet.getTimestamp(Field,Calendar), where calendar is a GMT+10:00 calendar, the resulting date is again one hour too early.

Does this sound plausible (are DATETIME fields stored as dates in ResultSets?), and is this the correct behaviour?

I figure that in order to solve this problem, I should set serverTimezone=GMT+10:00 and useTimeZone=true, as I assume that setting serverTimezone will inform JDBC how to interpret dates from MySQL. Does this setting also set the session timezone in MySQL? However I cannot seem to find or work out the correct syntax for setting serverTimezone to be an offset from GMT/UTC. I can only set it to timezones represented by strings (eg. GMT,MST,EST) which is of little use. Though I have found that setting serverTimezone=GMT and then interpreting the date with ResultSet.getTimestamp(Field,Calendar) using a GMT Calendar produces the desired result, however this feels a little clunky...

Any help would be much appreciated.

Statement.executeQuery() hangs (no replies)

$
0
0
Hi,

I have several databases at one server. When I run a query using JDBC driver from a Java application, the query against one database hangs while the same query against other databases work fine via different connections. This problem occurs sporadically.

I wonder if other people get the same problem? I am pretty sure a connection to the database has been established when Statement.executeQuery() hangs.

The version of mysql used is 5.0.51a-24+lenny4-log, and my JDBC driver is 5.0.8.

Thanks a lot for help.
Viewing all 884 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>