Syntac error in JSP and MySQL
HI guys,
I have been facing another problem. The codings below. Worked well with my JSP and Access database.
Then I transfered my database to MySQL and it gives out syntax error in my SQL statement.
CODE1:
sql = "SELECT Week, SUM (Total_Inspected) AS ins, SUM (Total_Rejected) AS rej, SUM (Total_Accepted) AS acc, SUM (DPPM) AS dpp, SUM (Yield) AS yeel FROM Calc_Data WHERE MONTH(Inspect_Date) ="+bulann+" GROUP BY Week";
ResultSet rs = stm.executeQuery(sql);
CODE2:
String query = "SELECT ID, Model, Lot_No, Lot_Qty, Inspected_By, Reject_Desc, Area_Concerned, Location, Remark FROM OQA WHERE Customer = '"+customer+"' AND Inspect_Date =#"+tarikh+"#";
ResultSet rs = stmt.executeQuery(query);
Whenever you have this type of problem, the easiest
solution is to take the sql and try running it
directly. For MySQL, you can either use the
command-line client, or there are a few graphical
clients that can handle it. Just type in the query,
run it, and let the database itself tell you what the
error is.
In any case, you probably won't find much useful
advice on a JSP forum, esp. since the problem has
absolutely nothing to do with JSP.Indeed - I agree with this. - MOD
Similar Messages
-
Unable to connect JSP and MySQL
Hi, I am new to this forum
I've started developing web pages using JSP
I've the problem connecting JSP and MySQL database. I've created the page that retrive records from mysql table. But the connection fail to access to database it gives me this error:
org.apache.jasper.JasperException: Exception in JSP: /retreive_book.jsp:15
The code is:
12: <%
13: //Class.forName("com.mysql.jdbc.Driver").newInstance();
14: Class.forName("org.gjt.mm.mysql.Driver");
15: connection = DriverManager.getConnection(connectionURL,"","");
16: statement = connection.createStatement();
17: rs = statement.executeQuery("SELECT * FROM books_detail");
18: %>
And the connectionURL parameter has this value:
String connectionURL = "jdbc:mysql://localhost:3306/books?username=;password=";
root cause msg is:
java.sql.SQLException: Invalid authorization specification: Access denied for user 'nobody'@'localhost' (using password: NO)
Please can anyone help me. It is 3 days now trying to do that but not succeded yetHi
Yes It is true that my MySQl installation its username is root. So how should put that in the url. Cause I did that but it didn.t work
String connectionURL= "jdbc:mysql://localhost:3306/books?username=root;password=";
If I write in that manner is it correct for root username or should I put a single quote
Thanks -
JSP and MySql Connectivity in Fedora core 4
Dear all,
We are developing software using JSP and MySql on Fedora Core 4 platform and are unable to find the connectivity for JSP and MySql. Can anybody help....Dear all,
We are developing software using JSP and MySql on Fedora Core 4 platform and are unable to find the connectivity for JSP and MySql. Can anybody help.... -
PleaseHelp on jsp and Mysql connectivity and a lot of exception errors
Hi,
I am Trying to connect a JSP page with Mysql database. I am having a lot of probelms. After having a lot of problems in connecting the JSp with Mysql. Intilally it was giving me the exception error that " NO appropriate driver was found. After modifying the URl it was fine. Now It is giving the Following errors.
servlet.ServletException: Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream ** BEGIN NESTED EXCEPTION ** java.io.IOException MESSAGE: Unexpected end of input stream
In a window before loading the Explorer page it is giving the following error that The port 8081 is already in use and i should expand to other ports. Noraml JSP Files which used to work before are also not working .
Internal Tomcat JWSDP is alos not working. If i try to start the server it says that port 8081 is already in USe . A java.net.connection exception is also occuring. The normal JSP files are also not working. What is Happening. I am also giving the code i have writted. PLease tellme why so many exception errors are occuring.
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8081/mis_project", "root", " ");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select study_semester FROM Semester");
while(rs.next()) {
%>
<option value="<%= rs.getString("Study_Semester") %>">
</option>
<% }
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(con!=null) con.close();
I am trying to connect to Mysql and automatocally populate a field in a Form in later JSp pages i intend to record the data entered in these fields into other tables.<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/myDB?user=username&password=mypass");
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
String cat = "";
try{
cat = request.getParameter("category");
}catch(NullPointerException npe){}
ResultSet rs = stmt.executeQuery("SELECT id,fullname FROM users WHERE category LIKE '%motor%' AND subcategory like '%"+cat+"%'");
%>
This piece gets a category parameter from a form post and uses it to search for a specific category in a database table. I think maybe u need to download JConnector from mysql site and unzip it to the classes folder of your WEB-INF in Tomcat server...... i hope this helps a bit -
Problems with JSP and MySql bean.
Hi,
I'm new to JSP and I'm having some problems with it. I'm trying to do a simple login where a java class (bean?) handles the SQL injektion. I have deployed the page on tomcat and it works fine, except that the sqlinjektion does basically nothing. I have installed the mysql driver. I think there is something wrong with the java class, or the way im calling it. It does not produce any error. But its like it would never actually process the java code, because ive tried to append things to error string to see what is going on, nothing happens. everything stay null, no exceptions are thrown. If I implement the code to JSP itself, it does load the driver and print exception that there is no connection to database (which is correct). What am I missing? Code follows:
the sqlhandler:
public abstract class SqlInjektor {
private static String Database = "*****";
private static String serverName = "localhost:3306";
private static String usrName="******";
private static String passw="******";
* @return Connection
public static Connection createConnection(String error){
Connection mySqlCon = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
catch(Exception E){
PrintWriter out = response.getWriter();
out.println("lol");
String url = "jdbc:mysql://" + serverName + "/" + Database + "?user=" + usrName + "&password=" + passw;
try{
mySqlCon = DriverManager.getConnection(url);
catch (Exception E){
E.printStackTrace(System.out);
return mySqlCon;
* Metodi saa sy�tteen��n SQL komennon, jonka se suorittaa sek� palauttaa komennon tulokset.
* @param command
* @return ResultSet
public static ResultSet querySQL(String command,String error, Connection con){
ResultSet rs = null;
try{
Statement stmt = con.createStatement();
rs = stmt.executeQuery(command);
catch(Exception E){
E.printStackTrace(System.out);
return rs;
the jsp page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isErrorPage="false" %>
<%@ page import="java.sql.*" %>
<%@page import="ot3.User"%>
<%@page import="ot3.SqlInjektor"%>
<%@page import="Javax.servlet.jsp.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>vastaanotto</title>
</head>
<body>
<%! String id;
String password;
String error = new String("Error!\n");
User user;
%>
<% user = new User();
session.putValue("currentUser",user);
id = request.getParameter("authName");
password = request.getParameter("Password");
Connection conn=null;
ResultSet rs=null;
conn = SqlInjektor.createConnection(error);
if(conn!=null){
out.println("conn ok!");
rs = SqlInjektor.querySQL("SELECT * FROM user WHERE id='" + id +"' AND password='" + password+"' COLLATE latin1_bin;",error,conn);}
try {
if (rs!= null && rs.next()){
user.setID(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setPassword(rs.getString("password"));
user.setClearance(rs.getInt("clearance"));
if(rs.getString("addedby")!=null)
user.setAdder(rs.getInt("addedby"));
if(rs.getString("lastmodifier")!=null)
user.setModifier(rs.getInt("lastmodifier"));
rs.close();%>
ONNISTU!
<%}
else {
out.println(error);
} catch (SQLException e) {
out.println(e.getMessage());
}%>
</body>
</html>Hi,
I'm new to JSP and I'm having some problems with it. I'm trying to do a simple login where a java class (bean?) handles the SQL injektion. I have deployed the page on tomcat and it works fine, except that the sqlinjektion does basically nothing. I have installed the mysql driver. I think there is something wrong with the java class, or the way im calling it. It does not produce any error. But its like it would never actually process the java code, because ive tried to append things to error string to see what is going on, nothing happens. everything stay null, no exceptions are thrown. If I implement the code to JSP itself, it does load the driver and print exception that there is no connection to database (which is correct). What am I missing? Code follows:
the sqlhandler:
public abstract class SqlInjektor {
private static String Database = "*****";
private static String serverName = "localhost:3306";
private static String usrName="******";
private static String passw="******";
* @return Connection
public static Connection createConnection(String error){
Connection mySqlCon = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
catch(Exception E){
PrintWriter out = response.getWriter();
out.println("lol");
String url = "jdbc:mysql://" + serverName + "/" + Database + "?user=" + usrName + "&password=" + passw;
try{
mySqlCon = DriverManager.getConnection(url);
catch (Exception E){
E.printStackTrace(System.out);
return mySqlCon;
* Metodi saa sy�tteen��n SQL komennon, jonka se suorittaa sek� palauttaa komennon tulokset.
* @param command
* @return ResultSet
public static ResultSet querySQL(String command,String error, Connection con){
ResultSet rs = null;
try{
Statement stmt = con.createStatement();
rs = stmt.executeQuery(command);
catch(Exception E){
E.printStackTrace(System.out);
return rs;
the jsp page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isErrorPage="false" %>
<%@ page import="java.sql.*" %>
<%@page import="ot3.User"%>
<%@page import="ot3.SqlInjektor"%>
<%@page import="Javax.servlet.jsp.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>vastaanotto</title>
</head>
<body>
<%! String id;
String password;
String error = new String("Error!\n");
User user;
%>
<% user = new User();
session.putValue("currentUser",user);
id = request.getParameter("authName");
password = request.getParameter("Password");
Connection conn=null;
ResultSet rs=null;
conn = SqlInjektor.createConnection(error);
if(conn!=null){
out.println("conn ok!");
rs = SqlInjektor.querySQL("SELECT * FROM user WHERE id='" + id +"' AND password='" + password+"' COLLATE latin1_bin;",error,conn);}
try {
if (rs!= null && rs.next()){
user.setID(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setPassword(rs.getString("password"));
user.setClearance(rs.getInt("clearance"));
if(rs.getString("addedby")!=null)
user.setAdder(rs.getInt("addedby"));
if(rs.getString("lastmodifier")!=null)
user.setModifier(rs.getInt("lastmodifier"));
rs.close();%>
ONNISTU!
<%}
else {
out.println(error);
} catch (SQLException e) {
out.println(e.getMessage());
}%>
</body>
</html> -
Listener error with dg4odbc and mysql
Hi all,
First of all, sorry for my English, I'm learning :-)
I'm trying to create a dblink from oracle to mysql, but for now this seems impossible. I have read lots of manuals and post, but no way. I can connect to remote mysql server with "isql my_portal", so, unixodbc and the mysql driver for odbc are working in the server.
The oracle database 10.2 is installed in a Red Hat 64 bits server. Due to hsodbc for 10.2 is only for 32bit i installed the gateway version for 11g without problems (no errors showed, so...) But I have always the same error: "TNS-12541: TNS:no listener dg4odbc" But my configuration seems correct. Can anyone find the error in my config? Thank you
This is the documentation that I have used:
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=561033.1
After apply the modifications to the configuration files, this is what lsnrcntl start says:
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/liste ner.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/srv-bbdd1/listener/alert/lo g.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=1.0.2.42)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=cl-oracle.jferrer.es)(PO RT=1521)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 16-MAR-2011 10:54:38
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/list ener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/srv-bbdd1/listener/alert/ log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=1.0.2.42)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "SQLServerA3" has 1 instance(s).
Instance "SQLServerA3", status UNKNOWN, has 1 handler(s) for this service...
Service "dbjde" has 1 instance(s).
Instance "dbjde", status UNKNOWN, has 1 handler(s) for this service...
Service "my_portal" has 1 instance(s).
Instance "my_portal", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
Then I try tnsping to my_portal:
tnsping:
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 16-MAR-2011 11:36:45
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SID = my_portal)) (HS=OK))
TNS-12541: TNS:no listener
Some information:
- unixodbc driver is in /usr/lib64 (libodbc.so)
- mysql for odbc driver is in /usr/lib64 (libmyodbc.so)
This is my odbc.ini (/etc/odbc.ini):
[ODBC Data Sources]
odbcname = my_portal
[my_portal]
Description = my_portal
Driver = MySQL
SERVER = 1.0.2.98
PORT = 3306
USER = root
PASSWORD = desarrollo
Database = portal_clientes
[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib64/libmyodbc.so
Setup=/usr/lib64/libodbcmyS.so
Added to listener.ora
(SID_DESC =
(SID_NAME = my_portal)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = dg4odbc)
(ENVS = LD_LIBRARY_PATH=/u01/app/oracle/product/10.2.0/db_1/hs/lib:/u01/app/oracle/product/10.2.0/db_1/lib:/usr/lib64)
Added to tnsnames.ora
my_portal =
(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = localhost)
(PORT = 1521)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = my_portal))
(HS=OK))
initmy_portal.ora
HS_FDS_CONNECT_INFO=my_portal
HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
HS_FDS_TRACE_LEVEL=ON
UseCursorLib=0
set ODBCINI=/etc/odbc.iniThank you for the response. The problem was the solved when change the 1.2.0.40 to 42 :-)
Another issue I saw is your ORACLE_HOME - did you install DG4ODBC in your 10.2 OH?Yes, the documentation said that is certified to work with Oracle 10.2.0.4 that is our version, is this a problem? (¿...?) I had no problem to install dg4odbc with the universal installer.
But I have another problems now. I can't remember the exact error, but my first problem was solved adding this line to initmy_portal.ora:
HS_FDS_QUOTE_IDENTIFIER="'"
Now, when I try to make a select oracle returns this:
ORA-00942: la tabla o vista no existe
[MySQL][ODBC 3.51 Driver][mysqld-5.1.41-3ubuntu12.10]Table 'portal_clientes.CLIENTES' doesn't exist {42S02,NativeErr = 1146}[MySQL][ODBC 3.51 Driver][mysqld-5.1.41-3ubuntu12.10]Table 'portal_clientes.CLIENTES' doesn't exist {42S02,NativeErr = 1146}
ORA-02063: 2 lines precediendo a MY_PORTAL_DBLINK
The table exists, I'm sure, and if I change the query to other tables the result is the same: the table doesn't exist. Any idea?
Thank you for the help -
Hi all,
Requirement:
I have a front end in which there are 3 fields name,age,status when ever I enter values these should be stored in mysql db.and here in status I have check constraint it should be either 'Active' or 'Inactive'
when ever I enter Active into status text field It should store as 1 in db
when ever I enter Inactive into status text field it should store as 0 in db .
How to acheive this please give me some suggestions
Thanks in Advance....Also, rather than submit the page on clicking the 'save' button, have an onClick() attribute added to the save button that calls a javascript function. In the javascript function, do some basic client side validation before allowing the function to submit to the server. Example: name cannot be empty, age cannot be empty, age must be a number (no letters), either active or inactive must be checked.
-
dear all,
I am new to sql and database programming and am a bit confussed about the line:
Connection Conn = DriverManager.getConnection("jdbc:mysql:dbname");
the jdbc is the what is the dbname??? is it the address of the database on your hard drive??? how is it formated??? what is the file that you need to point to??? how dies this work
Thanks THi
the JDBC Url should have the following format
jdbc:mysql://<hostname>:<port>/<database>
If your MySQL Database is running at your local host
and it is using the default port than you can use
jdbc:mysql://127.0.0.1:3306/test
jdbc -> Means you are trying to open a jdbc connection
mysql -> MySQL Databse Driver
(make sure that your MySQL jdbc driver is registered)
to connect to the test database on your MySQL Server
regards
thsimon -
Hi, I am pretty new using MySQL. I have doubt on the datetime field used in MySQL.
Here is my issue. I have a datetime column, called CreatedDate.
I store the strTodayDate in it.
Date dtTodayDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strTodayDate = sdf.format(dtTodayDate);
But when I retrieve it and display on page, it gave me 2005-05-26 09:25:19.0 <--- extra dot & zero.
Can someone please kindly advise me why?
Thank you very much.When storing date time it does not realy store it in the same format you give it.
and when you retrive the date time the my sql simply dont know in which format did you save it. So it will give it in a standerd format.
When you store and retrive date/time value use java.sql.DateTime / Date / Time objects and always use methods like setDate and getDate. do not convert them to strings.
I my applications I also used to store dates as long values (in millisecs) in column type BIGINT instead of actual date time column type. That way also you can overcome this problem since my sql will not treat the value as a date but as a long number. -
hi all,
we have a MySQL database containing a TAGLOG table and the following columns:
TAGNUMBER, int
TAGVALUE, float
TAGTIMESTAMP, timestamp
a Schneider Electric Factory Cast HMI Modicon PLC module keeps logging data from the PLC onto the TAGLOG table.
we need to set-up a form to allow the user to select:
start date: ____
start time: ____
end date: ___
end time: ___
so we can build a query, send to the database and when thre Result Set is received show on a table format.
Any assistance in setting up a user friendly form to enter above dates and times will be appreciated.
thanks in advance for any assistance.
Trajanothis is a problem i need to deal with soon, and am wondering the best way for it as well.
the easiest (and quickest) would be a simple text box for each, where user types date and time as a string, with separators eg 13/03/1982 or 13:32
Otherwise three drop-down lists, one for day, one for month & one for year. Similar for time.
for me it's not worth creating or buying some fancy 'calendar' control, but i'm sure there are many available. -
Jsp and mysql... best aproach
hi all ! I need to do some checking of some data before submiting my form. So my idea is that depending on what you select in a list/ menu the values of another list changes. I know I could do this with javascript. The problem is that I want to make the values from the second list reflect data that is stored in a database.
So how can I do this ?
Any advice, recomendations, links are apreciated.Me, I would put an onChange event on the first select box that submits a form to retrieve the content of the second select box.
There are ways to do it without a submit though:
1) dynamic select box. It involves putting all possible values for the second select box into a huge javascript array and you use the first select box to index into this array.
2) Ajax. With ajax you can fetch the data for the second select box in the background.
3) hidden iframe. If you don't want to use ajax directly you could load a page in a hidden iframe that will mimic the ajax call.
For all three options there are numerous articles on the web, just search for them. -
Need a host free about jsp and mysql in order to test my subject project.
Please show me a address host free . I need it to test my project. Thank so much
Try Google Apps. Totally free.
- Saish -
An error when using JSP to activate connection between Javabean and MySQL
I just input two paramenters in the input.htm, then click button 'submit' to
run output.jsp, then activate adder.getSum(); This function is to add two
number, save the sum to the MySQL database, and return the sum. I think the
java code and jsp file are no problem. A guess it's the problem relating to
the servlet engine trying to talk to the Javabean. Should I set some
envirenment or other? Please take a look. If necessary, I will attach my jsp
and java codes later.
The error is as below:
Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error)
that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException:
at org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:273)
root cause org.apache.jasper.JasperException:
at org.apache.jasper.runtime.JspRuntimeLibrary.convert(JspRuntimeLibrary.java:184)
I just selected some. Thanks,Yes, I'd be curious to see your code. In principle that should work.
-chicagoJava -
JSP with MYSQL on linux and windows2k
I am using a linux box as a web server with tomcat and mysql. I aslo have a mirror on a Win2k machine running the same environment.
I have a jsp file that uses a bean to update the database and it works on the win2k environment but not linux.
In windows I see error messages in the tomcat console, how do I see these message on linux?
Thank you,
Paul.Did you check ALL of the files?
There are files named "localhost_log.TODAYSDATE.txt", there are files named "catalina_log.TODAYSDATE.txt", and there's a file called "catalina.out".
"catalina.out" appears to contain information very similar to the DOS output screen on the Windows platform.
If those files don't have what you're looking for, then you'll have to get help from someone with more expertise than myself! -
Problems with java and mysql error: 1064
Hello,
I have been struggling with the following java code for a day. I ALWAYS get the following error code : 1064 and I just can't figure out why. I am trying to insert data into a mysql table.
Can anyone please help?
Thanks in advance,
Julien.
package com.newedgegroup.pnr.misc;
import java.sql.BatchUpdateException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
* @author Julien Martin
public class RunDataCopy {
public static void main(String[] args) throws ClassNotFoundException, Exception , ParseException {
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
String url_source = "jdbc:as400://as400a.calyonfinancial.com";
Connection con_source = DriverManager.getConnection(url_source, "upload", "upload");
Class.forName("com.mysql.jdbc.Driver");
String url_target = "jdbc:mysql://localhost:3306/pnr";
Connection con_target = DriverManager.getConnection(url_target, "root", "");
Statement stat_source = con_source.createStatement();
// ResultSet rs_source = stat_source.executeQuery("select * from QS36F.GMIST4F1 po");
String query = "SELECT " +
" sum (po.PGROSS) AS OPTION_PREMIUM, " +
"po.PFIRM, " +
"po.POFFIC, " +
"po.PACCT, " +
"po.PTDATE, " +
"po.PRR, " +
"po.PEXCH, " +
"po.PSUBEX, " +
"po.PFC, " +
"po.PSYMBL, " +
"po.PCLASS, " +
"po.PSUBCL, " +
"po.PSUBTY, " +
"po.PSDSC1, " +
"po.PCTYM, " +
"po.PSTRIK, " +
"po.PCLOSE, " +
"po.PUNDCP, " +
"po.PCURSY, " +
"po.PEXPDT, " +
"po.PLTDAT, " +
"po.PMULTF, " +
"po.PPTYPE, " +
"po.PBS " +
"FROM QS36F.GMIST4F1 as po " +
"WHERE " +
"0 = 0 " +
"AND po.PFIRM = 'I' " +
"AND po.POFFIC = '349' " +
"AND po.PRECID in ('T','B','Q') " +
"AND po.PSUBTY != ' ' " +
"AND po.PCMNT1 != ' E' " +
"AND po.PCMNT1 != ' A' " +
"GROUP BY " +
"po.PFIRM, " +
"po.POFFIC, " +
"po.PACCT, " +
"po.PTDATE," +
"po.PRR, " +
"po.PEXCH, " +
"po.PSUBEX," +
"po.PFC, " +
"po.PSYMBL, " +
"po.PCLASS, " +
"po.PSUBCL, " +
"po.PSUBTY, " +
"po.PSDSC1, " +
"po.PCTYM, " +
"po.PSTRIK, " +
"po.PCLOSE, " +
"po.PUNDCP, " +
"po.PCURSY, " +
"po.PEXPDT, " +
"po.PLTDAT, " +
"po.PMULTF, " +
"po.PPTYPE, " +
"po.PBS ";
// System.out.println(query);
ResultSet rss = stat_source.executeQuery(query);
StringBuffer sb = new StringBuffer("");
SimpleDateFormat df_s = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat df_t = new SimpleDateFormat("yyyy-MM-dd");
con_target.setAutoCommit(false);
Statement stat_target = con_target.createStatement();
int i = 0;
try {
while (rss.next()) {
i++;
sb.append("INSERT INTO `pnr`.`pnr_transaction` (").append("\n");
sb.append("`FIRM_ID`,").append("\n");
sb.append("`OFFICE_NUMBER`,").append("\n");
sb.append("`ACCOUNT_NUMBER`,").append("\n");
sb.append("`SALESMAN`,").append("\n");
sb.append("`EXCHANGE_CODE`,").append("\n");
sb.append("`SUBEXCHANGE`,").append("\n");
sb.append("`FUTURES_CODE`,").append("\n");
sb.append("`SYMBOL`,").append("\n");
sb.append("`ACCOUNT_CLASS_CODE`,").append("\n");
sb.append("`SUB_CLASS_CODE`,").append("\n");
sb.append("`SECURITY_SUB_TYPE`,").append("\n");
sb.append("`SECURITY_DESCRIPTION_LINE`,").append("\n");
sb.append("`CONTRACT_YR_MON`,").append("\n");
sb.append("`STRIKE_PRICE`,").append("\n");
sb.append("`CLOSING_MARKET_SETTLEMENT_PRICE`,").append("\n");
sb.append("`UNDERLYING_CLOSE_PRICE`,").append("\n");
sb.append("`PRODUCT_CURRENCY_SYMBOL`,").append("\n");
sb.append("`EXPIRATION_DATE`,").append("\n");
sb.append("`LAST_TRADING_DATE`,").append("\n");
sb.append("`MULTIPLICATION_FACTOR`,").append("\n");
sb.append("`PRODUCT_TYPE_CODE`,").append("\n");
sb.append("`CATEGORY_ID`,").append("\n");
sb.append("`MARKET_TYPE_ID`,").append("\n");
sb.append("`TAX_STATUS_ID`,").append("\n");
sb.append("`AMOUNT`").append("\n");
sb.append(") VALUES (").append("\n");
sb.append("'").append(rss.getString("PFIRM")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("POFFIC")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PACCT")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PRR")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PEXCH")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PSUBEX")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PFC")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PSYMBL")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PCLASS")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PSUBCL")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PSUBTY")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PSDSC1")).append("'").append(",").append("\n");
sb.append("'").append(rss.getString("PCTYM")).append("'").append(",").append("\n");
sb.append(rss.getString("PSTRIK")).append(",").append("\n");
sb.append(rss.getString("PCLOSE")).append(",").append("\n");
sb.append(rss.getString("PUNDCP")).append(",").append("\n");
sb.append("'").append(rss.getString("PCURSY")).append("'").append(",").append("\n");
sb.append("'").append(df_t.format(df_s.parse(rss.getString("PEXPDT")))).append("'").append(",").append("\n");
sb.append("'").append(df_t.format(df_s.parse(rss.getString("PLTDAT")))).append("'").append(",").append("\n");
sb.append(rss.getString("PMULTF")).append(",").append("\n");
sb.append("'").append(rss.getString("PPTYPE")).append("'").append(",").append("\n");
//sb.append(rss.getString("PBS")).append(",");
sb.append("1").append(",").append("\n");
sb.append("1").append(",").append("\n");
sb.append("1").append(",").append("\n");
sb.append(rss.getString("OPTION_PREMIUM")).append("").append("\n");
// sb.append(df_t.format(df_s.parse(rss.getString("PTDATE")))).append(",");
sb.append(") ").append("\n");
System.out.println(sb.toString());
// stat_target.executeUpdate(sb.toString());
stat_target.addBatch(sb.toString());
// stat_target.executeUpdate(sb.toString());
if (i == 2) {
break;
stat_target.executeBatch();
con_target.commit();
} catch (BatchUpdateException be) {
System.out.println("be: "+be.getErrorCode());
System.out.println("be: "+be.getMessage());
be.printStackTrace();
System.out.println("be: "+i);
} catch (SQLException se) {
System.out.println("se: "+se.getErrorCode());
System.out.println("se: "+i);
}What is the error message?
I advice you to use prepared statement for batch inserting.
Maybe you are looking for
-
Ipod touch screen went black and then started flashing. Then the turn off slide comes up. Restored multiple times and didn't work. Ipod works with Itunes fine (can put music and podcasts on the ipod), but can't take songs off of the ipod. Using windo
-
Dynamic For loop in Oracle 10g
Hi , my requirement is to write dynamic for loop , Some thing similar to below plsql block, But I am getting error , please suggest declare lv_text varchar2(200); begin lv_text:='select * from some_table '; for i in (lv_text) loop null; end loop; end
-
URGENT: Help reqd with wwsbr_explorer
Jerry, I am able to create a sitemap by using the above package and passing it the values that I need for site and render type. However, I do not know the values for p_header and p_footer. Can you please help me out. Also, I would like to supress the
-
Can't get safari to open with home page
I have set google as my homepage in Preferences, but Safari invariably opens with the last page I had used before quitting. I've tried both "Set as Current Page" (being on google, of course), as well as typing in google's URL. Any suggestions? Thank
-
Dropdown menu not showing entries
Hello. I created a fillable form in Acrobat XI using text boxes, check boxes, and dropdown menus. The first issue is when the form is opened on a tablet running Windows 8.1 and using Acrobat Reader XI, the fields are not highlighted. The second issue