Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a SQL Server 2012 database in the network of my company.
I can access to this database to observe the tables etc... with SQL Server Management Studio giving the following :
Server type : Database Engine
Server name : xxx-yyy-zzz.eu.company.corp, number_of_port
Authentication : Windows Authentication
Username and password
I also know the name of the database and nothing more.
I would like to connect a new Java program I am writing with Eclipse to this SQL Server database. But I have never connected or even used a SQL Server before so I have no idea how to do it. I understood reading some other posts that I need a driver, but I don't understand where I need to install this driver, which driver and what I need to do to extract data from the database in my Java program.
Could you please tell me more about it ? Thank you :)
I suggest you start here with this Microsoft documentation, Microsoft JDBC Driver for SQL Server.
Looks like you can download the actual driver from Microsoft JDBC Driver 6.0 for SQL Server.
What you need to do may vary depending on the operating system you are using however the above driver looks to be pretty inclusive for Linux, Windows and also works with Azure, Microsoft's cloud offering.
The Programming Guide for JDBC SQL Driver has a number of links explaining what you will need to do and Building the Connection URL describes the actual connect string.
This stack overflow post has a sample program. Java program to connect to Sql Server and running the sample query From Eclipse.
You may also find How to connect to Microsoft SQL Server database using Eclipse to be helpful.
Just remember, you need Eclipse IDE for Java EE developers to access
the database. It contains tools for database development e.g. database
explorer. The Eclipse IDE for Java Developers doesn't contain those
tool by default. FYI, I am using Eclipse Java EE IDE for Web
Developers, Version: Kepler Service Release 2.
Some time back I had problems with Microsoft JDBC Driver and used open source JTDS. I do not remember exact problems, but JTDS worked just fine for me.
So, code to connect to database may look like:
//Not required anymore - just for demonstration. Driver class must be in class path
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection dbCon = DriverManager
.getConnection("jdbc:jtds:sqlserver://{db_host}:[db_port]/{Database Name};domain={user Windows domain};user={user id};password={user password}");
PreparedStatement stmt = dbCon.prepareStatement("SELECT GETDATE()");
ResultSet resSet = stmt.executeQuery();
while (resSet.next()) {
System.out.println(resSet.getString(1));
}
System.out.println("Done");
dbCon.close();
Maven dependency for JTDS driver:
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
BTW: Maybe there is a newer version available...
Related
I downloaded the latest Bitnami Jaspersoft (7.1.1) appliance, and when creating a PostgreSQL (JDBC) Data Source to a PostgreSQL via the Jaspersoft web front-end, the "Test Connection" button always fails with an error message "Connection failed". I downloaded the appliance as an OVM, I'm running it as a VirtualBox VM.
To ensure it's not due to networking issues, I installed psql in the appliance (it's a Debian box) to ensure it can actually connect to my PostgreSQL database (it's a separate server), and it connects well via command-line psql, so I assume the problem is a JDBC issue. I also tried opening port-forwarding 5432 via ssh, so that I can connect to my database via localhost.
My question is, how can debug connection problems in Jaspersoft, or identify what is causing the failure? Jaspersoft 7.1.1 appliance comes with MySQL and PostgreSQL JDBC drivers already installed, and I was able to create and successfully test a new Data Source to the local standard MySQL database, so that driver definitely works. I couldn't find any log files that would output any error messages when testing the connection.
The appliance comes with the following JDBC driver: /opt/bitnami/apache-tomcat/lib/postgresql-9.1-903.jdbc4.jar. It also includes the following files:
/opt/bitnami/apps/jasperserver/buildomatic/conf_source/db/postgresql/jdbc/postgresql-9.4-1210.jdbc41.jar
/opt/bitnami/apps/jasperserver/buildomatic/conf_source/db/postgresql/jdbc/postgresql-9.4-1210.jdbc42.jar
/opt/bitnami/apps/jasperserver/buildomatic/conf_source/db/app-srv-jdbc-drivers/postgresql-9.4-1210.jdbc41.jar
/opt/bitnami/apps/jasperserver/buildomatic/conf_source/ieCe/lib/postgresql-9.4-1210.jdbc41.jar
I'm unfamiliar with Tomcat, and although I understand java code, I'm not a full-stack java developer. How can I debug this problem?
After hacking on it for a while, I tried replacing the file /opt/bitnami/apache-tomcat/lib/postgresql-9.1-903.jdbc4.jar with the latest jdbc driver from jdbc.postgresql.org, and restarted the server. This did the trick! I wonder why the latest Jaspersoft Server appliance comes pre-installed with such an old jdbc driver. Also, installing it via the web-based interface as per the documentation didn't work either.
Answering my own question here just in case anyone else gets stuck with the same problem!
Postgresq by default is not allow connection from remote hosts. It possible if you running postgresql and jaspersoft on different hosts.
How to Allow Remote Access to PostgreSQL database
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
how would i saver the state of a java program so that if i had to give the copy from the dist folder that it would still work on another computer without for instance the other computer having MySQL installed etc
Instead of MySQL, you can use 100% Java relational databases such as Apache Derby, H2 Database engine or the HyperSQL. Starting at Java 6, the SDK included Derby as JavaDB. There is a Getting Started Guide in the Java DB 10 (JDK 8) documentation.
You can include the .jar files in your project and use the databases using a JDBC connection without installing any additional software. Application servers such as Glassfish and JBoss uses, by default, Derby and H2 for the example databases and JMS messages. Usually, administrators change that databases (using a different JDBC URL connection) in production.
Notes on using JavaDb or Derby
Derby (and JavaDB) can run as a network server or an embedded one. The network server allows connections from multiple users/programs. An embedded server only works with the application that starts the engine. Both server types are included in the .jar files and you can control them using JDBC and the library API.
For a network server, you must start the server and use a JDBC URL connection like jdbc:derby://localhost:1527/dbname;create=true where a port and a database are defined or a connection such as jdbc:derby://localhost:1527/c:\temp\myDatabase;create=true with the location of the database. You may check the Vogella's tutorial for Apache Derby
// use the Derby JDBC driver
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
// connect to the database
Connection connect = DriverManager
.getConnection("jdbc:derby://localhost/c:/temp/db/FAQ/db");
// execute a Query
PreparedStatement statement = connect
.prepareStatement("SELECT * from USERS");
ResultSet resultSet = statement.executeQuery();
:
For a embedded server, you must use a different JDBC driver and URL. The Connection URL is like jdbc:derby:MyDbTest;create=true, and does not include a port. There is an explanation in the Derby's documentation.
// use the Embedded Derby JDBC driver
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
// connect to the database
Connection connect = DriverManager
.getConnection("jdbc:derby:MyDBTest;create=true");
// execute a Query
PreparedStatement statement = connect
.prepareStatement("SELECT * from USERS");
ResultSet resultSet = statement.executeQuery();
:
Method 1:
If there is no very complicated data like you would save it in a table of a database, you could use for example a simple config file.
Method 2:
Otherwise you could just use a sqllite database. That's like a database in a single file, that doesn't need a server to run.
Method 3:
You could use a remote database. You would have access to the data from anywhere. (Even without copying the Application every time)
Method 4:
Use a "Java" database, like for example H2.
Method ...: There are many other things you can do, to achieve this!
I have a server with Windows Server 2003 SP2 and third party application developed with Java SE version 5.0. This app connecting to external database server via configured ODBC source.
In my ODBC sources I have configured source to external MS SQL server. As I can say it uses this driver: SQLSRV32.DLL Version: 2000.86.3959.00. When I configure this source and test conenction it says that connection is successfull.
Many years external DB server runned under MS SQL Server 2008 and all was OK. But now they migrated to MS SQL Server 2012 and my java app lost connection to it with exception like this:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The incoming
tabular data stream (TDS) remote procedure call (RPC) protocol stream
is incorrect. Parameter 1 (""): Data type 0x38 is unknown.
How can I fix connection? Is there any driver I need to install for Windows or Java?
You are using an outdated and obsolete driver version. The error is a result of a bug in the SQLServer 2000 driver
. To correct the issue you need to update the driver to a newer version. For more specific information on the cause and resolution of the error, see:
Microsoft KB Article 915834
To upgrade to later (2005+) drivers, you will be required update the jar files and the connection string used as described in the article. If you do not have access to the code to make a change, you will need to contact Microsoft and request an available hotfix that fixes the bug in the 2000 drivers as described in the KB and shown here:
To resolve this problem immediately, contact Microsoft Product Support
Services to obtain the hotfix. For a complete list of Microsoft
Product Support Services telephone numbers and information about
support costs, visit the following Microsoft Web site:
http://support.microsoft.com/contactus/?ws=support
It may also be possible to find a later 'patched' version of the driver .dll file. I was able to find an example of the download at this URL: Sqlsrv32.dll 2000.086.4412.00 which is a later version than the one you are using and may correct the issue. If that doesn't work search around for downloads later than this one, which as you can see is build #4412. If you download from a site other than Microsoft,make sure you do a virus scan of the file before using it.
I am new to Oracle Database and database management systems in general. At the moment I am developing a Java program that needs to use Oracle Database (contest requirement) but I am wondering, is my program only going to work on my local machine?
I used SQLite before, but that is a server-less database management system and it only connects to a file. Instead, JDBC connects to an URL like this:
Connection connection = null;
connection = DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:mkyong","username","password");
So, from what I understand, if I send my program to a friend for example, in order for my program to work, Oracle Database must be already installed and configued on his PC.
With SQLite, I only needed to include a *.sqlite file with the program that the program used.
Am I missing something here? Thanks!
If your Oracle database is accessible by your friend's computer because
- it is on the same network
- there is a VPN involved
- your database is on the internet
then your friend's computer needs an Oracle JDBC driver (a small jar) but not its own installation of the Oracle DBMS.
Otherwise an installation of Oracle is required. Consider Oracle Database XE that according to the website "Oracle Database 11g Express Edition is an entry-level, small-footprint database based on the Oracle Database 11g Release 2 code base. It's free to develop, deploy, and distribute; fast to download; and simple to administer." There are Windows 64, Windows 32 and Linux 64 downloads available.
im using Eclipse Helios Java EE IDE for Web Developers,Version: 1.3.0. connection with derby embeded jdbc driver is workin fine but i cannot make connection with derby client jdbc driver... what should i do to make it work,please help me...
connection with derby embeded jdbc driver is workin fine but i cannot make connection with derby client jdbc driver
Providing details (what you did, what didn't work, etc) is generally useful to get good answers. Here are some things to check though:
make sure derbyclient.jar is on the classpath
make sure you are using org.apache.derby.jdbc.ClientDriver as driver class
make sure the URL follows the following format jdbc:derby://<host>:<port>/<database>
make sure the network server has been started(!)