Newbie: Problem with jdbc-odbc and MS SQL server 2005
I'm on win vistax64 with SQLSERVER 2005 and I have set up the odbc source as system dsn using the SQL Native Client driver with SQL authentication and the connectivity test in the end succeeds.
I'm trying to make a simple web app that will connect to the database and perform simple querries. It's a school assignment.
I'm using the jdbc-odbc bridge because it's the simplest way to do it and it's what we were shown in class.
I get the following irritating error:
"Cannot establish a connection to jdbc:odb:sstmdb using sun.jdbc.odbc.JdbcOdbcDriver ([Microsoft][ODBC Driver Manager] Data source name not found and no default driver specifies)".
I'm working with netbeans 5.5.1 and this error is what I get when in the runtime tab I try to connect with the jdbc-odbc. I get a similar error in the logs when I try to run the app on the j2ee server.
This is the java class that establishes the connection.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connector {
private static final String dbUrl="jdbc:odbc:sstmdb";
private static final String user="kimon";
private static final String password="jackohara";
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(dbUrl,user,password);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
return conn;
}It has worked perfectly on my school PC with winXP and MSDE2000.
What am I missing?
Ok, help came from an other way where I was inquiring about a different problem:
Connectivity works fine by using User DSN instead of System DSN for the ODBC source.
Similar Messages
-
Problem with jdbc:odbc returning incorrect number of rows.
Hello,
Am sure i have done something stupid, but i have an issue with jdbc:odbc ....
It is a simple sceanrio that i have coded umpteen times before ...
I have the following ....
1. Connection to DB2 on an IBM i5 (I apologise for not using native drivers from jt400.jar, but i had an ODBC code example and was in a rush - no excuse i know)
2. Statement object created from connection above
3. A string with my SQL in it
4. A result set for the results.
These are created as follows:
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(ODBCSource, userID, password);
if (con == null) {
// error handling not relevant here
} else {
Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String SQL = "select * from table";
ResultSet rs = s.executeQuery(SQL);
i then try to loop ....
while (rs.next() )
// stuff
however, i only ever get one result .... if i stick in the check for isLast, the first loop hits this check, i get my little status message, and the loop ends.
while (rs.next() )
if (rs.isLast() )
System.out.println("I am on last record");
BUT if i run the SQL
"select count(*) from table" ... i get a count of 148 !!
I tried setting the FetchSize through setFetchSize(), but made no difference.
This is running on a JBoss server 4.2.1GA, JDK is "jdk1.6.0_02" .... i have a suspicion that this may be a JBoss specfic issue, as this exact code runs just fine on the Domino platform that it was originally on, if this is the case, i apologise for wasting everyones time .... but would still appreciate any pointers you can give me.
CheersHello,
Thanks for the reply, I am not sure i follow what you are saying.
I only mentioned JBoss as it is the application server that we have deployed to and because the orignal code ran fine on a Domino server, I will take your advice and try to run it through in debug rather than running actually on the application server.
Am i incorrect in my assumption that if "select count(*) from table" gives a count of 148, i should expect 148 records in a result set created from "select * from table" ? This is all rather new to me so i apologise if this is incorrect, I'd love to know why this is incorrect so i dont make similar mistakes in future.
Also, If i run this same code on the previous platform, i get 148 iterations of the code contained within
while (rs.next() ) { ... }
When the war file is deployed to JBoss, the same SQL statement gives a result set that only iterates once for
while (rs.next() ) { ... }
The previous platform as I say was domino, but it was running as a lotus notes java agent (despite not using any notes documents etc) as it happened to be where the web pages that call this process were located. It is possible that some of the main code has changed as I had cut and paste the code into a servlet using MyEclipse, but i have double checked the bit that does this SQL request and it is identical
To complete the picture, the new servelt is then called from the action tag on the submit form on a JSP, when it ends the servlet redirects via the requestdispacher to success or failure jsp pages depending on the outcome of the processing.
Thank you again for your help. -
ODBC connect to SQL Server 2005 from Oracle 10.2.0.3 32bit Linux
I’m unable to establish a connection from Oracle 10.2.0.3 32bit Linux to SQL Server 2005.
The ODBC driver is the 32bit DataDirect 5.3 drivers and when I do a status on the listener it does have a handler for SQLDB
Any help is appreciated.
Received the following error:
SQL> select count(*) from columns@SQLDB;
select count(*) from columns@SQLDB
ERROR at line 1:
ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
[Generic Connectivity Using ODBC]DRV_InitTdp: DB_ODBC_INTERFACE (718): ; [C077]
Could not find symbol 'SQLAllocConnect' in dynamic library
DB_ODBC_INTERFACE (722): ; [C079] Failed to load dynamic library
'/app/DataDirect/lib/libodbc.so'
ORA-02063: preceding 3 lines from SQLDB
-----Contents of trace file------------------
Oracle Corporation --- THURSDAY JUL 10 2008 10:17:16.251
Version 10.2.0.3.0
hoagprd (2): ; hoagprd Entered.
HOACONN.C (244): ; [Generic Connectivity Using ODBC] version: 4.8.2.0.0080
HOACONN.C (288): ; Class version: 250
hoagprd (2): ; hoagprd Exited with retcode = 0.
hoainit (3): ; hoainit Entered.
(0): ; connect string is: defTdpName=SQLDB;SYNTAX=(ORACLE8_HOA, BASED_ON=
ORACLE8, IDENTIFIER_QUOTE_CHAR="", CASE_SENSITIVE=CASE_SENSITIVE_QUOTE);
BINDING=<navobj><binding><datasources><datasource name='SQLDB' type='GENERIC_
ODBC_FOR_HS' connect='SQLDB'><driverProperties/></datasource></datasources><
remoteMachines/><environment><optimizer noFlattener='true'/><misc
year2000Policy='-1' consumerApi='1' sessionBehavior='4'/><queryProcessor
parserDepth='2000' tokenSize='1000' noInsertParameterization='true'
noThreadedReadAhead='true' noCommandReuse='true'/><debug driverTrace='true'
generalTrace='true'/></environment></binding></navobj>
ORACLE GENERIC GATEWAY Log File Started at 2008-07-10T10:17:16
hoainit (3): ; hoainit Exited with retcode = 0.
hoalgon (7): ; hoalgon Entered. name = dbuser.
sysbase.c (677): ; libodbcinst.so: cannot open shared object file: No such
file or directory
DB_ODBC_INTERFACE (718): ; [C077] Could not find symbol 'SQLAllocConnect' in
dynamic library
DB_ODBC_INTERFACE (722): ; [C079] Failed to load dynamic library '/app/
DataDirect/lib/libodbc.so'
DB_ODBC_INTERFACE (727): ; [C077] Could not find symbol 'SQLAllocConnect' in
dynamic library
DRV_InitTdp: DB_ODBC_INTERFACE (718): ; [C077] Could not find symbol '
SQLAllocConnect' in dynamic library
DB_ODBC_INTERFACE (722): ; [C079] Failed to load dynamic library '/app/
DataDirect/lib/libodbc.so'
nvRETURN (./drv_bind.c 230): -2220
nvRETURN (./nav_bind.c 298): -2220
hoalgon (7): ; hoalgon Exited with retcode = 28500.
hoaexit (6): ; hoaexit Entered.
hoaexit (6): ; hoaexit Exited with retcode = 0.
(0): ; Closing log file at THU JUL 10 10:17:16 2008.
--------------end of trace file ---------------
--------TNS entry ----------
SQLDB=
(DESCRIPTION =
(ADDRESS =(PROTOCOL = TCP)
(Host = oracledbhost)
(Port = 1521)
(CONNECT_DATA = (SID =SQLDB)
(HS=OK)
-------Listener.ora entry----------
(SID_DESC=
(SID_NAME=SQLDB)
(ORACLE_HOME=/app/oracle10g/product/10.2)
(PROGRAM=hsodbc)
-------initSQLDB.ora----------
# This is a sample agent init file that contains the HS parameters that are
# needed for an ODBC Agent.
# HS init parameters
HS_FDS_CONNECT_INFO = SQLDB
HS_FDS_TRACE_LEVEL = 4
HS_FDS_TRACE_FILE_NAME=/app/DataDirect/SQLDB.trc
HS_FDS_SHAREABLE_NAME=/app/DataDirect/lib/libodbc.so
# ODBC specific environment variables
set ODBCINI=/app/DataDirect/odbc.ini
------odbc.ini entry------------
[SQLDB]
Driver=/app/DataDirect/lib/ivmsss23.so
Description=DataDirect 5.2 SQL Server Wire Protocol
Address=SQLServerhost,1401
AlternateServers=
AnsiNPW=Yes
ConnectionRetryCount=0
ConnectionRetryDelay=3
Database=SQLServerDB
LoadBalancing=0
LogonID=
Password=
QuotedId=No
SnapshotSerializable=0The error message is indicating problems loading the driver manager.
A common issue on Linux (especially on Suse Linux) is related to library caching. First of all make sure you add the LD_LIBRARY_PATH to your listener.ora file to guarantee the correct libraries will be loaded. Your SID section will then look like:
(SID_DESC=
(SID_NAME=SQLDB)
(ORACLE_HOME=/app/oracle10g/product/10.2)
(ENVS=LD_LIBRARY_PATH=/app/oracle10g/product/10.2/lib:/app/DataDirect/lib)
(PROGRAM=hsodbc)
After changing the listener.ora file stop and start the listener.
Details about the set up can be found in Metalink note:
Note.264567.1 P216. How To Setup Generic Connectivity - HSODBC - on Linux
If this does not help enable strace and check out from which location libodbc.so is being loaded.
Please be also aware HSODBC has been desupported 15th of March. As you start a new project you should proceed with the follow up product DG4ODBC. -
ODBC Drivers for SQL Server 2005 on AIX for OWB connect
Hi All -
I have a problem whereby I am trying to connect OWB with SQL Server 2005. The problem statement follows: -
Infrastructure: -
OWB Server installed on AIX
Oracle Installed on AIX
SQL Server 2005 source on Windows
OWB Client on windows XP
My problem is: -
I am trying to connect OWB with SQL Server 2005 for which I have to create heterogenous source entry in Oracle home. But AIX box does not have any ODBC drivers installed and hence I can not configure a DSN on the same. Can any one suggest where can I get these drivers and their installation steps.
Thanks in advance!
Arun
Edited by: Uni.... on Jun 2, 2009 10:50 PMI was not able to find DG4ODBC anywhere.
Somehow I managed to get a copy of Data Drivers from Data Direct and configured ODBC.INI file as below: -
ODBC Data Sources
DB2 Wire Protocol=DataDirect 6.0 DB2 Wire Protocol
Informix Wire Protocol=DataDirect 6.0 Informix Wire Protocol
Oracle Wire Protocol=DataDirect 6.0 Oracle Wire Protocol
Sybase Wire Protocol=DataDirect 6.0 Sybase Wire Protocol
Teradata=DataDirect 6.0 Teradata
SQLServer Wire Protocol=DataDirect 6.0 SQL Server Wire Protocol
MySQL Wire Protocol=DataDirect 6.0 MySQL Wire Protocol
PostgreSQL Wire Protocol=DataDirect 6.0 PostgreSQL Wire Protocol
Greenplum Wire Protocol=DataDirect 6.0 Greenplum Wire Protocol
ODBC
IANAAppCodePage=4
InstallDir=/u01/app/ODBC
Trace=0
TraceFile=odbctrace.out
TraceDll=/u01/app/ODBC/lib/odbctrac.so
AMS
Driver=/u01/app/ODBC/lib/ddmsss24.so
Description=DataDirect 6.0 SQL Server Wire Protocol
Address=10.240.20.154,1433
Database=AMS
My TNSName.Ora file is shown below: -
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DWHDEV =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = aixdevdb2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = DWHDEV)
AMS =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.240.20.154)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = AMS)
(HS = OK)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
Listener.Ora file is as below: -
# listener.ora Network Configuration File: /u01/app/oracle/product/10/db/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10/db)
(PROGRAM = extproc)
(SID_DESC =
(SID_NAME = AMS)
(ORACLE_HOME = /u01/app/oracle/product/10/db)
(PROGRAM = hsodbc)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = aixdevdb2)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
INITHSODBC file for this source is initAMS.ora is configured as: -
HS_FDS_CONNECT_INFO = AMS
HS_FDS_TRACE_LEVEL = 4
HS_FDS_TRACE_FILE_NAME = /u01/app/ODBC/log.log
HS_DB_NAME = MSSQL
HS_FDS_SHAREABLE_NAME = /u01/app/ODBC/lib/odbc.so
# ODBC specific environment variables
#set ODBCINI= /u01/app/ODBC/odbc.ini
I have tested the DSN created in ODBC.INI file using example appplication that comes by default with datadirect drivers and that is connecting to database and fetching data as per query supplied, but when I am trying to create connecting from OWB to SQL Server it is failing with following error: -
ORA-28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA-02063: preceding 2 lines from OWB_188
Even database link is giving same error message.
I have followed all the steps which are necessary to configure Heterogeneous connectiviyt including restarting listener, but no luck.
Any comments -
CR with VS 2003 Oracle vs SQL Server 2005
VS2003
Windows XP
All Crystal Reports designed using "push" model (Seting the Report Document's SetDataSource property using a single table dataset)
I have a large VS2003 application (90+ Crystal Reports) using an Oracle database. The client wants to switch to SQL Server 2005. The application works with SQL Server "as is" except for the Crystal Reports. A query engine error is generated. The tables/views are quite simple using only integers, decimals, char and varchar columns, no datetime columns. The dataset's Name and datatable's Name are the same, the only difference is the data provider used. Microsoft's Oracle Data provider vs Microsoft's SQL Server Data provider. Any thoughts? Any workarounds?.
I am in the process of converting the application to VS2008 and the problem does not exist in the VS2008 version. Crystal Reports converted from VS2003 to VS2008 work with either database/data provider.,
Edit: It appears that Oracle does not differentiate between datatypes decimal and int32. Any thoughts. (Not the problem)
Edited by: spooky102 on Aug 17, 2009 6:40 PM
Edited by: spooky102 on Aug 17, 2009 6:42 PM
Edited by: spooky102 on Aug 17, 2009 7:31 PMAn assumption here is that your .NET 2003 app is using the bundled version of CR(?) - version 9.1. If that is the case, make sure you have updated your install with SP1:
https://smpdl.sap-ag.de/~sapidp/012002523100009301312009E/crnet11win_en.zip
Next, see if this blog will help you in troubleshooting the issue:
/people/ludek.uher/blog/2009/03/02/troubleshooting-issues-with-vs-net-datasets-and-crystal-reports
re:
It appears that Oracle does not differentiate between data types decimal and int32.
Not sure how this relates to Crystal Reports as such? But let's work on one issue per thread. If you want to work the data type issue more, please create a new thread. Otherwise, these things get too messy...
Ludek -
ColdFusion and MS SQL Server 2005 Enterprise Edition
Trying to get ColdFusion (Developers Edition) to communicate
with MS SQL Server 2005 (Enterprise Edition). I have ColdFusion
running on username = admin; password = as set up when installed.
Have also tried setting up a user account with my Windows desktop
username and password in case ColdFusion needed to be logged on as
the same user as the SQL server. I have full admin permissions on
the SQL Server (with Windows authentication), and am the database
"owner" of the database on the server. In either ColdFusion login
case, when I try to "add a data source", with driver = Microsift
SQL Server, I get.....
Connection verification failed for data source: CFtoVolcano
java.sql.SQLException: [Macromedia][SQLServer JDBC
Driver][SQLServer]Login failed for user 'kewing'.
The root cause was that: java.sql.SQLException:
[Macromedia][SQLServer JDBC Driver][SQLServer]Login failed for user
'kewing'.
Went to help files (troubleshooting area) and verified that
the local web browser (IIS) and Cold Fusion ARE running. Next step
takes me to "Change ColdFusion user account" which starts with
"Open Control Panel and select ColdFusion 8 App Server and click
Startup". I don't see that choice in MyComputer/ControlPanel. Not
even sure if this is going to ba another dead end anyway!!!
HELP! This shouldn't be this difficult! I'm not using some
weird version of SQL!To use the default SQL drivers bundled with CF you need to
use SQL authentication (which is disabled by default I think) in
SQL Server 2005. If you enable SQL (mixed mode) authentication and
create a user you can then add the data source in the CF admin.
Alternatively, in order to use integrated windows
authentication with SQL server your CF service needs to run as
specific user. (It sounds like you've already done this) and you
will need to use Microsoft's JDBC driver
Driver download (MS JDBC Driver)
http://www.microsoft.com/downloads/details.aspx?familyid=C47053EB-3B64-4794-950D-81E1EC91C 1BA&displaylang=en
Connecting with Integrated authentication (MS JDBC Driver)
http://msdn2.microsoft.com/en-us/library/ms378428.aspx#Connectingintegrated -
Exception in JDBC forName for MS SQL Server 2005
I am new to JDBC application development. I am writing a JDBC application using Visual Studio 2005. I need to connect my application to MS SQL Server 2005. I have installed the JDBC driver 3.0. Also Java runtime version 1.6 is intalled on my machine.
I am writing a simple code to connect to the SQL server. I have set the CLASSPATH in inviromnet variable list. Here is the code
package MyJDBCApp;
import java.sql.*;
import java.util.*;
public class Connect
public static void main(String[] args)
String url = "jdbc:sqlserver://NOI1-501791:1433;databaseName=test;user=sa; password=asdf1234;";
Connection con;
Statement stmt;
try
Class.forName("com.sqlserver.jdbc.SQLServerDriver");
catch (java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con = DriverManager.getConnection(url);
if (con != null)
con.close();
catch (SQLException ex)
System.err.println("SQLException: " + ex.getMessage());
When I try to debug this application everytime I am getting Class not found exception. Can anybody help me to resolve this problem.
Thanks in advance. Regards ZubairI am writing a JDBC application using Visual Studio 2005
Say what!? Are we talking about Visual J++ here!?!?!? -
Hi
I am using XP SP3 and I had previous successful installation for Primavera P6 8.3 with samples in the past, until my hard drive gave a message that’s its almost full, I tried to move the database to D:\ but I was stuck and lost connection with data base, I made uninstall for Primavera from add remove programs then made "Deinstalling Oracle Database XE" and followed all steps in the article http://docs.oracle.com/cd/B25329_01/doc/install.102/b25143/toc.htm#CIHDDHJD
to clean the registry and all traces of the old installation, and uninstalled Microsoft SQL server 2005 with all components,
When I re installed Primavera with sample projects everything was ok until the mid of oracleXE installation I had an error message , I run Primavera P6 8.3 setup again and chose to repair installation , this time gave me installation finished.
When I run Primavera I am not able to connect to Database, even traces of old installation like Alias names which was previously used exists .
When I connect to database through web home page I can log in as “system” but it has only HR in it, and users are 12 internal and 1 HR with no ADMPRM$PM.
I don’t think that sample projects are downloaded,
How to reconnect with database and install the Primavera sample projects. or even to clean all traces for the Primavera and data base oracleXE then make fresh re install , Thanks. ZeyadHi
I am using XP SP3 and I had previous successful installation for Primavera P6 8.3 with samples in the past, until my hard drive gave a message that’s its almost full, I tried to move the database to D:\ but I was stuck and lost connection with data base, I made uninstall for Primavera from add remove programs then made "Deinstalling Oracle Database XE" and followed all steps in the article http://docs.oracle.com/cd/B25329_01/doc/install.102/b25143/toc.htm#CIHDDHJD
to clean the registry and all traces of the old installation, and uninstalled Microsoft SQL server 2005 with all components,
When I re installed Primavera with sample projects everything was ok until the mid of oracleXE installation I had an error message , I run Primavera P6 8.3 setup again and chose to repair installation , this time gave me installation finished.
When I run Primavera I am not able to connect to Database, even traces of old installation like Alias names which was previously used exists .
When I connect to database through web home page I can log in as “system” but it has only HR in it, and users are 12 internal and 1 HR with no ADMPRM$PM.
I don’t think that sample projects are downloaded,
How to reconnect with database and install the Primavera sample projects. or even to clean all traces for the Primavera and data base oracleXE then make fresh re install , Thanks. Zeyad -
Comparing Oracle and MS SQL Server 2005
Hi!
I'm looking for documents which compare
features, price etc og the database and database related development-projects
I'm looking for resources that describe the terminology used of MS and Oracle for their db's.
I'm also looking for "Feuerstein"-best-practices in MS-world.
And at last I'm looking for simple and complex scenarios comparing performance/features of these db's.
And if possible, I want them from some "independent" sources...
Can anyone help?
Best regards
Bjorn Dorr JensenHi Hans!
I think it would not be fair comparing Oracle 10g with SQL Server 2000.
So thats why I'm looking for comparison with SQL Server 2005,
but if you have something that compare Oracle 11 with SQL Server 2005,
let me hear about it :-)
The objective:
well, the last 2 years I worked with Oracle DB (tuning, pl/sql) in an serious manner.
and now I have to work with SQL Server (which I didn't work with the last 2 years),
so I'm interested in the differences.
For now it seems that many SQL Server features are primitive compared with Oracle, but Microsofts usability is much better.
O1.) But is it really more primitive or are I'm missing the nessessary experience with SQL Server? Thats some of the points I want to find out.
O2.) Analyzing our own requirements for features: when would it be better to use Oracle and when to use MS? How to make this measure-able?
Could one make an descision tree like:
when more than x users/day and clustering needed and db_size>y....
O3.) Should I promote in an environment with people only using MS-products,
promote the use of Oracle-DB? When will this be an good idea?
(I don't think it will be an good idea the other way around: moving from Oracle to MS SQL Server - or would it ;^)
Best Regards
Bjorn -
Connecting Xcelcius and MS SQL Server 2005
Hi All,
I need to create report dashboards in Xcelcius fetching data from MS SQL 2005 server. I've found different options for setting the connection between Xcelcius and MS SQL 2005, like using Reporting Service, using XML Maps etc. Which is the best option for setting up the connection?
Thanks and Regards,
Shyam.Shyam,
You may wish to refer the link below..
Re: Integration of the xCelsius and SQL Server 2005 database
What i suggest is, create web service to retrieve data from SQL database and call this WSDL url in your Xcelsius.
-Anil -
Client transport between SAP on Oracle 10G and MS SQL server 2005
Hi Folks,
We have a requirement where we have to do client export/import from SAP ECC 6.O running on Oracle 10g and to SAP ECC 6.0 running on MS SQL server 2005.I want to know whether SAP supports this and patch levels of all components two systems should be the same.
Thanks in advance,
Basis AdminNot recommendet because of potential :
- patch level inconsistency
- ABAP dictionary inconsistency (programs, tables)
- possible client independent configuration conflicts
existing config cen disturb "imported" client
imported config can ddisturb existing clients
If there are any inconsistencies mentioned above you are in trouble...
regards,
wojtek -
Ms Access problems with Jdbc Odbc!!!
Hi again people,
Im creating a GUI swing project connecting a database (MsAccess) to a dialog using the bridge driver,
The GUI is coming up but im getting runtime errors and the data does not go to the fields, the dialog and connection are in two files:
import java.awt.*;
import java.awt.event.*;
import java.sql.*; //SQL package for the statements
import javax.swing.*;
class DatabaseMan
public ResultSet m_resultSet; //recordset resulting from SQL query
public ResultSetMetaData m_rsmd; //used to get general info about the columns
private int m_nNumberOfFields; //number of fields in a recordset
private Connection conn;
private Statement stmt;
public DatabaseMan(String strSQLQuery)
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try //establish connection to the database
//try to get connection to the database
conn = DriverManager.getConnection("jdbc:odbc:db1");
//this is not where we update the database so we make it read only
stmt = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
m_resultSet = stmt.executeQuery(strSQLQuery);
catch(SQLException exSQL)
System.err.println("\n\n\t\t ***SQLException has" +
"been caught ***\n\n");
while ( exSQL != null)
System.err.println("\nSQLState : " + exSQL.getSQLState() );
System.err.println("\nMessage : " + exSQL.getMessage() );
System.err.println("\nVendor code : "+ exSQL.getErrorCode() );
System.err.println("\n");
exSQL = exSQL.getNextException();
catch( ClassNotFoundException e)
System.err.print("\n\n\tClassNotFoundException has"
+" been caught");
System.err.println( e.getMessage());
catch( java.lang.Exception ex )
ex.printStackTrace();
public void CloseConnection() //close connection to database
try
conn.close();
stmt.close();
m_resultSet.close(); //release the resources
catch (SQLException exSQL )
System.out.println("SQL Exception: " + exSQL.getMessage());
exSQL.printStackTrace(System.out);
public int getNoFields()
return m_nNumberOfFields;
} //end of DatabaseMan.java
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import DatabaseMan;
import javax.swing.*;
class DBviewer extends JDialog implements ActionListener
//JButtons to create toolbar
private JButton m_buttonFirst;
private JButton m_buttonNext;
private JButton m_buttonPrevious;
private JButton m_buttonLast;
private JButton m_buttonClose;
private JButton m_mainbuttonClose;
//textfields to transfer the data from database
private JTextField m_name;
private JTextField m_age;
private JTextField m_weight;
private JTextField m_professionalism;
private JTextField m_speed;
private JTextField m_acceleration;
private JTextField m_jump;
private JTextField m_stamina;
private JTextField m_bravery;
private JTextField m_fitness;
private JTextField m_experience;
//labels to identify the textfields
private JLabel m_labelname;
private JLabel m_labelage;
private JLabel m_labelweight;
private JLabel m_labelspeed;
private JLabel m_labelacceleration;
private JLabel m_labelprofessionalism;
private JLabel m_labeljump;
private JLabel m_labelstamina;
private JLabel m_labelbravery;
private JLabel m_labelfitness;
private JLabel m_labelexperience;
DatabaseMan m_DatabaseMan;
private String strSQLQuery1;
private String type1 = new String("");
public DBviewer(Frame parent, String caption, boolean bModal, String type)
super(parent,caption,true);
setSize(600,400);
setLocation( new Point(150 , 150 )); //position it pops up on screen.
setResizable(false);
strSQLQuery1 = new String("");
type1 = type;
//SQL query to show the horse database
if(type =="Horse")
strSQLQuery1 ="SELECT *" +
"FROM HORSE";
buildHorseGUI();
if(type =="Jockey")
strSQLQuery1 ="SELECT *" +
"FROM JOCKEY"+
" ORDER BY NAME";
buildJockeyGUI();
if(type =="Course")
strSQLQuery1 ="SELECT *" +
"FROM RACECOURSE"+
" ORDER BY NAME";
buildCourseGUI();
m_DatabaseMan = new DatabaseMan(strSQLQuery1);
/*try
{//reset values with default move up to top later
if(m_DatabaseMan.m_resultSet.first())
transferData(type1);
catch( SQLException exSQL)
System.out.println("SQL Exception: " + exSQL.getMessage());
exSQL.printStackTrace(System.out);
public void buildHorseGUI() //construct the horse GUI
buildDefaultGUI(); //build default buttons and toolbar
m_labelname = new JLabel(" Horse Name:",JLabel.CENTER);
m_labelname.setBackground(Color.blue);
m_labelname.setForeground(Color.white);
m_labelage = new JLabel("Age: ",JLabel.CENTER);
m_labelage.setBackground(Color.blue);
m_labelage.setForeground(Color.white);
m_labelweight = new JLabel("Weight(p): ",JLabel.CENTER);
m_labelweight.setBackground(Color.blue);
m_labelweight.setForeground(Color.white);
m_labelspeed = new JLabel("Speed:",JLabel.CENTER);
m_labelspeed.setBackground(Color.blue);
m_labelspeed.setForeground(Color.white);
m_labelacceleration = new JLabel("Acceleration:",JLabel.CENTER);
m_labelacceleration.setBackground(Color.blue);
m_labelacceleration.setForeground(Color.white);
m_labelprofessionalism = new JLabel("Professionalism:",JLabel.CENTER);
m_labelprofessionalism.setBackground(Color.blue);
m_labelprofessionalism.setForeground(Color.white);
m_labeljump = new JLabel("Jump:",JLabel.CENTER);
m_labeljump.setBackground(Color.blue);
m_labeljump.setForeground(Color.white);
m_labelstamina = new JLabel("Stamina:",JLabel.CENTER);
m_labelstamina.setBackground(Color.blue);
m_labelstamina.setForeground(Color.white);
m_labelbravery = new JLabel("Bravery:",JLabel.CENTER);
m_labelbravery.setBackground(Color.blue);
m_labelbravery.setForeground(Color.white);
m_labelfitness = new JLabel("Fitness:",JLabel.CENTER);
m_labelfitness.setBackground(Color.blue);
m_labelfitness.setForeground(Color.white);
m_labelexperience = new JLabel("Experience",JLabel.CENTER);
m_labelexperience.setBackground(Color.blue);
m_labelexperience.setForeground(Color.white);
//creation of textfields to hold the data
//making them non-editable and b/ground of black with white text
m_name = new JTextField(20);
m_name.setEditable(false);
m_name.setBackground(Color.black);
m_name.setForeground(Color.white);
m_age = new JTextField(2);
m_age.setEditable(false);
m_age.setBackground(Color.black);
m_age.setForeground(Color.white);
m_weight = new JTextField(3);
m_weight.setEditable(false);
m_weight.setBackground(Color.black);
m_weight.setForeground(Color.white);
m_speed = new JTextField(2);
m_speed.setEditable(false);
m_speed.setBackground(Color.black);
m_speed.setForeground(Color.white);
m_acceleration = new JTextField(2);
m_acceleration.setEditable(false);
m_acceleration.setBackground(Color.black);
m_acceleration.setForeground(Color.white);
m_professionalism = new JTextField(2);
m_professionalism.setEditable(false);
m_professionalism.setBackground(Color.black);
m_professionalism.setForeground(Color.white);
m_jump = new JTextField(2);
m_jump.setEditable(false);
m_jump.setBackground(Color.black);
m_jump.setForeground(Color.white);
m_stamina = new JTextField(2);
m_stamina.setEditable(false);
m_stamina.setBackground(Color.black);
m_stamina.setForeground(Color.white);
m_bravery = new JTextField(2);
m_bravery.setEditable(false);
m_bravery.setBackground(Color.black);
m_bravery.setForeground(Color.white);
m_fitness = new JTextField(2);
m_fitness.setEditable(false);
m_fitness.setBackground(Color.black);
m_fitness.setForeground(Color.white);
m_experience = new JTextField(2);
m_experience.setEditable(false);
m_experience.setBackground(Color.black);
m_experience.setForeground(Color.white);
//create a panel to hold this data
Panel data = new Panel();
data.setLayout(new GridLayout(0,4));
data.setBackground(Color.blue);
data.add(m_labelname);
data.add(m_name);
data.add(m_labelage);
data.add(m_age);
data.add(m_labelweight);
data.add(m_weight);
data.add(m_labelspeed);
data.add(m_speed);
data.add(m_labelacceleration);
data.add(m_acceleration);
data.add(m_labelprofessionalism);
data.add(m_professionalism);
data.add(m_labeljump);
data.add(m_jump);
data.add(m_labelstamina);
data.add(m_stamina);
data.add(m_labelbravery);
data.add(m_bravery);
data.add(m_labelfitness);
data.add(m_fitness);
data.add(m_labelexperience);
data.add(m_experience);
getContentPane().add(data, BorderLayout.CENTER);
public void buildDefaultGUI() //construct the default components for GUI
JToolBar wndToolBar = new JToolBar();
wndToolBar.setBackground(Color.green);
wndToolBar.setFloatable(false);
m_buttonFirst = new JButton( new ImageIcon( "graphic/myFirst.gif" ) );
m_buttonPrevious = new JButton(new ImageIcon( "graphic/myPrevious.gif" ) );
m_buttonNext = new JButton(new ImageIcon( "graphic/myNext.gif" ) );
m_buttonLast = new JButton(new ImageIcon( "graphic/myLast.gif" ) );
m_buttonClose = new JButton(new ImageIcon( "graphic/myClose.gif" ) );
m_mainbuttonClose = new JButton("CLOSE");
// implement action listener
m_buttonFirst.addActionListener(this);
m_buttonPrevious.addActionListener(this);
m_buttonNext.addActionListener(this);
m_buttonLast.addActionListener(this);
m_buttonClose.addActionListener(this);
m_mainbuttonClose.addActionListener(this);
//set the tool tips for each of the button
m_buttonFirst.setToolTipText( "Display first record" );
m_buttonPrevious.setToolTipText( "Display previous record" );
m_buttonNext.setToolTipText( "Display next record" );
m_buttonLast.setToolTipText( "Display last record" );
m_buttonClose.setToolTipText( "Close this window and return to game" );
m_mainbuttonClose.setToolTipText( "Close this window and return to game" );
m_mainbuttonClose.setBackground(Color.green);
//add these buttons to the toolbar
wndToolBar.add( m_buttonFirst );
wndToolBar.add( m_buttonPrevious );
wndToolBar.add( m_buttonNext );
wndToolBar.add( m_buttonLast );
wndToolBar.addSeparator(); //separator in the toolbar
wndToolBar.add( m_buttonClose );
getContentPane().add(wndToolBar, BorderLayout.NORTH);
getContentPane().add(m_mainbuttonClose, BorderLayout.SOUTH);
public void buildCourseGUI() //construct the course GUI
buildDefaultGUI();
public void buildJockeyGUI() //construct the jockey GUI
buildDefaultGUI();
public void actionPerformed( ActionEvent evt)
//button first record is pressed
if( evt.getSource() == m_buttonFirst )
try
if( m_DatabaseMan.m_resultSet.first() )
transferData(type1);
catch (SQLException exSQL )
System.err.println( exSQL.toString() );
//button next record is pressed
if( evt.getSource() == m_buttonNext )
try
if(!m_DatabaseMan.m_resultSet.isLast())
if(m_DatabaseMan.m_resultSet.next())
transferData(type1);
catch (SQLException exSQL )
System.err.println( exSQL.toString() );
//previous button is pressed
if( evt.getSource() == m_buttonPrevious )
try
if( !m_DatabaseMan.m_resultSet.first())
if(m_DatabaseMan.m_resultSet.previous())
transferData(type1);
catch (SQLException exSQL )
System.err.println( exSQL.toString() );
//last button is pressed
if( evt.getSource() == m_buttonLast )
try
if(m_DatabaseMan.m_resultSet.last())
transferData(type1);
catch (SQLException exSQL )
System.err.println( exSQL.toString() );
// close button(s) pressed
if( evt.getSource() == m_buttonClose)
setVisible( false );
dispose(); //return the dialog window resources
m_DatabaseMan.CloseConnection();
if( evt.getSource() == m_mainbuttonClose)
setVisible( false );
dispose(); //return the dialog window resources
m_DatabaseMan.CloseConnection();
public void transferData(String type1) throws SQLException //return a String
if(type1 =="Horse")
//transfer horse details
m_name.setText(m_DatabaseMan.m_resultSet.getString("NAME"));
m_professionalism.setText(m_DatabaseMan.m_resultSet.getString("PROFESSIONALISM"));
m_speed.setText(m_DatabaseMan.m_resultSet.getString("SPEED"));
m_stamina.setText(m_DatabaseMan.m_resultSet.getString("STAMINA"));
m_weight.setText(m_DatabaseMan.m_resultSet.getString("WEIGHT"));
m_experience.setText(m_DatabaseMan.m_resultSet.getString("EXPERIENCE"));
m_fitness.setText(m_DatabaseMan.m_resultSet.getString("FITNESS"));
m_jump.setText(m_DatabaseMan.m_resultSet.getString("JUMP"));
m_age.setText(m_DatabaseMan.m_resultSet.getString("AGE"));
m_bravery.setText(m_DatabaseMan.m_resultSet.getString("BRAVERY"));
m_acceleration.setText(m_DatabaseMan.m_resultSet.getString("ACCELERATION"));
if(type1 =="Jockey")
m_name.setText(m_DatabaseMan.m_resultSet.getString("NAME"));
m_age.setText(m_DatabaseMan.m_resultSet.getString("AGE"));
if(type1 =="Course")
//transfer course details not implemented yet
} //end of class DBviewer
I ve set up an odbc driver and the database has data in it but I still get this run time error an no data is transfered to the dialog box
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1525)
at sun.jdbc.odbc.JdbcOdbcResultSet.reWordAsCountQuery(JdbcOdbcResultSet.java:6268)
at sun.jdbc.odbc.JdbcOdbcResultSet.calculateRowCount(JdbcOdbcResultSet.java:6061)
at sun.jdbc.odbc.JdbcOdbcResultSet.initialize(JdbcOdbcResultSet.java:150)
at sun.jdbc.odbc.JdbcOdbcStatement.getResultSet(JdbcOdbcStatement.java:420)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:250)
at DatabaseMan.<init>(DatabaseMan.java:34)
at DBviewer.<init>(DBviewer.java:83)
at MainWindow.actionPerformed(MainWindow.java:266)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
at java.awt.Component.processMouseEvent(Component.java:3715)
at java.awt.Component.processEvent(Component.java:3544)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2593)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
at java.awt.Container.dispatchEventImpl(Container.java:1200)
at java.awt.Window.dispatchEventImpl(Window.java:914)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
Im really stuck!!! any suggestions? thanks in advanceThank you for your response and sorry for the length
of code,
Thats was my first idea that it was asking for
or something I dont have but I checked my database and
I dont have any unusually large data entries (most
between 8-15 letters, the others are numbers) could it
be something wrong with how I've entered the database
in MsAccess, or am i barking up the wrong tree again!
Many thanks
RobI think you've misunderstood me. This has nothing to do with unusually large data entries, but rather the opposite. You are wrongly expecting data that is shorter than you think. When you call rs.getString(i) to retrieve a column value of a field, and you only want the first 5 characters in the column (instead of 10 or whatever the column size is), you would do something similar to the following:
String column_value = rs.getString(1).subtstring(0,5);The above expects a String that is at least 5 characters. Your problem is when your column value returned is less than the specified substring index ( in this case 5 ) it will throw an exception. If you changed your code to this, the error will not occur:
String column_value = rs.getString( 1 ).subtstring( 0, 5);
if ( column_value.length() > 5 )
column_value = column_value.substring( 0, 5 );
}Jamie -
Problems with JDBC-ODBC Driver
Hello,
I am trying to access a DSN on my windows with a dedicated DB driver of some company. so i used the JDBC-ODBC connector.
when launching the java code, and debugging the problem i get the following error:
DriverManager.getConnection("jdbc:odbc:priority32;UID=Manager;PWD=keren")
trying driver--className=com.mysql.jdbc.Driver,com.mysql.jdbc.Driver@16caf43--
trying driver--className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@66848c--
*Driver.connect (jdbc:odbc:priority32;UID=Manager;PWD=keren)
JDBC to ODBC Bridge: Checking security
No SecurityManager present, assuming trusted application/applet
JDBC to ODBC Bridge 2.0001
Current Date/Time: Tue Aug 12 07:50:37 VET 2008
Loading JdbcOdbc library
Allocating Environment handle (SQLAllocEnv)
hEnv=50338088
Allocating Connection handle (SQLAllocConnect)
hDbc=50338256
Connecting (SQLDriverConnect), hDbc=50338256, szConnStrIn=DSN=priority32;UID=Manager;PWD=keren
*Connection.getMetaData
*DatabaseMetaData.getDriverName
Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=6, len=300
tabula.dll
*DatabaseMetaData.getDriverVersion
Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=7, len=300
07.00.0000
*DatabaseMetaData.getDriverName
Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=6, len=300
tabula.dll
Driver name: JDBC-ODBC Bridge (tabula.dll)
*DatabaseMetaData.getDriverVersion
Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=7, len=300
07.00.0000
Driver version: 2.0001 (07.00.0000)
Caching SQL type information
*Connection.getMetaData
*DatabaseMetaData.getTypeInfo
Allocating Statement Handle (SQLAllocStmt), hDbc=50338256
hStmt=50339424
Get type info (SQLGetTypeInfo), hStmt=50339424, fSqlType=0
Number of result columns (SQLNumResultCols), hStmt=50339424
value=15
Get connection info string (SQLGetInfo), hDbc=50338256, fInfoType=10, len=300
03.52.0000
Fetching (SQLFetch), hStmt=50339424
Column attributes (SQLColAttributes), hStmt=50339424, icol=1, type=2
value (int)=12
Column attributes (SQLColAttributes), hStmt=50339424, icol=1, type=3
value (int)=129
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
CHAR
Get integer data (SQLGetData), hStmt=50339424, column=2
value=12
Get integer data (SQLGetData), hStmt=50339424, column=3
value=0
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
CHAR(1)
Get integer data (SQLGetData), hStmt=50339424, column=2
value=1
Get integer data (SQLGetData), hStmt=50339424, column=3
value=0
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
RCHAR
Get integer data (SQLGetData), hStmt=50339424, column=2
value=12
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
REAL
Get integer data (SQLGetData), hStmt=50339424, column=2
value=6
Get integer data (SQLGetData), hStmt=50339424, column=3
value=0
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
INT
Get integer data (SQLGetData), hStmt=50339424, column=2
value=4
Get integer data (SQLGetData), hStmt=50339424, column=3
value=0
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
UNSIGNED
Get integer data (SQLGetData), hStmt=50339424, column=2
value=4
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
TIME
Get integer data (SQLGetData), hStmt=50339424, column=2
value=10
Get integer data (SQLGetData), hStmt=50339424, column=3
value=0
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
DATE
Get integer data (SQLGetData), hStmt=50339424, column=2
value=11
Get integer data (SQLGetData), hStmt=50339424, column=3
value=0
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
DATE
Get integer data (SQLGetData), hStmt=50339424, column=2
value=9
Get integer data (SQLGetData), hStmt=50339424, column=3
value=0
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
DAY
Get integer data (SQLGetData), hStmt=50339424, column=2
value=4
Fetching (SQLFetch), hStmt=50339424
Get string data (SQLGetData), hStmt=50339424, column=1, maxLen=130
DECIMAL
Get integer data (SQLGetData), hStmt=50339424, column=2
value=3
Get integer data (SQLGetData), hStmt=50339424, column=3
value=0
Fetching (SQLFetch), hStmt=50339424
End of result set (SQL_NO_DATA)
*ResultSet.close
Free statement (SQLFreeStmt), hStmt=50339424, fOption=1
*ResultSet has been closed
Get connection info (SQLGetInfo), hDbc=50338256, fInfoType=44
int value=0
Get connection info (SQLGetInfo), hDbc=50338256, fInfoType=121
RETCODE = -1
ERROR - Generating SQLException...
SQLState(S1096) vendor code(0)
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Information type out of range
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetInfo(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.checkBatchUpdateSupport(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at WigsUpdate.main(WigsUpdate.java:25)
getConnection returning driver--className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@66848c--what can be done?
thank you very muchHimberJack wrote:
oh now i understand.
i got a very unknown company which supplied the ODBC driver, but they dont have java driver...
so I have nothing to do about it?The choices are find a different driver or use the one you have.
The one you have doesn't do batches.
Finding a different driver could involve the following.
- Buying one from somewhere else
- Pay someone to write one.
- Write a driver yourself.
All of those are somewhat dependent that the "unknown company" has an API that supports that. You (or someone) could also figure out the file format of the "unknown company" as well and then write one. -
OS in my PC is Windows7 Ultimate(64-bit), and I had JDK1.7.0_21(compatible with my PC), Oracle 10G ExpressEdition(32-Bit), ApacheTomcat7.0.11(compatible with my PC).
As my OS is 64-BIT, I accessed C:\Windows\SysWOW64\odbcad32 and I selected UserDSN tab->Add->Microsoft ODBC for Oracle->finish,tapply->ok. Then a Dialog Box appeared and I entered a DSN name=ramsdsn and my DATABASE USERID=rams in username->ok->apply->ok.
But when I tried to compile my program using:
DriverManager.getConnection("jdbc:odbc:ramsdsn","rams","rams");
I got an error:java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
Help me FRNZ.. I have been trying it for 7 days and I'm tired of it and I could not figured it yet...
THANKS in Advance...Wrong database is the most likely reason.
Note that the ODBC driver is not a good driver for MS SQL Server. It handles varchar as chars. So an insert of 'A' into a varchar(25) will end up with 'A' followed by 24 spaces. And that probably isn't what you want your varchars to do. -
Problem With Jdbc-Odbc BRidge Connection
I get The following error
SQLException:[Microsoft][ODBC Driver Manager] Invalid cursor state
when using the code
whats the problem with it
import java.sql.*;
public class Employee {
String DBurl;
Connection con;
public Employee(String url)
DBurl=url;
void queryTest()
String query="SELECT * FROM EmpTable";
ResultSet result;
Statement stmt;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e){
System.err.println("Class not Found Exception:");
System.err.println(e.getMessage());
try{
con=DriverManager.getConnection(DBurl,"myLogin","mypassword");
stmt=con.createStatement();
result=stmt.executeQuery(query);
System.out.println("ID"+"\t"+"Name"+"\t"+"Rate"+"\t"+"DeptID");
System.out.println("--"+"\t"+"----"+"\t"+"---"+"\t"+"----");
while(result.next());
String name=result.getString("Name");
int ID=result.getInt("ID");
float rate=result.getFloat("Rate");
int deptID=result.getInt("DeptID");
System.out.println(ID+"\t"+name+"\t"+rate+"\t"+deptID);
stmt.close();
con.close();
catch(SQLException ex){
System.err.println("SQLException:" + ex.getMessage());
public static void main(String args[])
Employee app = new Employee("jdbc:odbc:Employee");
app.queryTest();
}here's your mistake:
while(result.next()); // <--- the loop body is empty.Remove the semi-colon.
%
Maybe you are looking for
-
I update my iphone 5c ios 7.1.2 (i think) to ios 8.0.2, however when it was intalling it suddently stppoed and my iphone only displayed the itunes icon with the cable plug in in the screen. I searched all over the internet for the solution and it say
-
Is there a way to modify multiple PO lines in PeopleSoft 9.1?
Our users may need to modify the Contract on construction POs with 80+ lines. Obviously, doing this line by line is time-consuming. Has anyone developed a way to do this either through on-line or batch?
-
Unable to share files between two macs
I'm trying to setup my iMac and my wife's iMac to share files through an Airport Extreme base station. I turned file sharing on on both computers and I can now see my wife's computer in the sidebar of the finder window. It says "Not connected' in the
-
I have Acrobat extended pro 9.0 and cant install it properly
I have Acrobat extended pro 9.0 and cant install it properly
-
How to change amount in Bar chart in XML Publisher
Hi all, I want to change a amount in chart in INR. I have created one bar chart for report in which on x-axis i have displayed a Month-Year and on Y-axis i have displayed a Amount. But when i insert a chart it will automatically takes amount in Milli