473,786 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you connect a Java program to a database?

1 New Member
how to connect java with database?
Jan 23 '08 #1
8 1722
JosAH
11,448 Recognized Expert MVP
Google for 'jdbc'.

kind regards,

Jos
Jan 23 '08 #2
BigDaddyLH
1,216 Recognized Expert Top Contributor
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR
Jan 23 '08 #3
BigDaddyLH
1,216 Recognized Expert Top Contributor
Here is Sun's JDBC tutorial:

http://java.sun.com/docs/books/tutorial/jdbc/index.html
Jan 23 '08 #4
2008serela
4 New Member
Here is Sun's JDBC tutorial:

http://java.sun.com/docs/books/tutorial/jdbc/index.html
Hi,

First decide which database u want to connect it?

Only the three steps:

1.If it is in the Oracle then..

String query="Select * from emp_table";
class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con=DriverManag er.getConnectio n("jdbc:odbc:<d atasourcename>" );
PreparedStateme nt ps=con.prepareS tatement(query) ;
ResultSet rs=ps.execute() ;

2.If it is for MsAcess then

the above steps are same only the driver and class.forName changes ..
now i forget it later i will send it.

Pls try the above coding and reply is must.If it is wrong Pls send the correct answer...

bye takecare!

by
ela
Jan 24 '08 #5
shaileshkumar
36 New Member
import java.sql package
Load the driver
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;

the above method throws ClassNotFoundEx ception

establish the connection
Connection con=DriverManag er.getConnectio n("URL","userid ","pwd")
the method in the above will throw SQLException

PreparedStateme nt ps=con.prepareS tatement("sql query");

the method above throws SQLException

AND

after doing with the database operations

close the connections
con.close();
this throws SQLException
Jan 24 '08 #6
2008serela
4 New Member
import java.sql package
Load the driver
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;

the above method throws ClassNotFoundEx ception

establish the connection
Connection con=DriverManag er.getConnectio n("URL","userid ","pwd")
the method in the above will throw SQLException

PreparedStateme nt ps=con.prepareS tatement("sql query");

the method above throws SQLException

AND

after doing with the database operations

close the connections
con.close();
this throws SQLException

Hi,

Pls do the above code within the try block
try{

<code>
}
catch(SQLExcept ion exception){
}


try this.......
Jan 24 '08 #7
ajos
283 Contributor
Hi,

First decide which database u want to connect it?

Only the three steps:

1.If it is in the Oracle then..

String query="Select * from emp_table";
class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con=DriverManag er.getConnectio n("jdbc:odbc:<d atasourcename>" );
PreparedStateme nt ps=con.prepareS tatement(query) ;
ResultSet rs=ps.execute() ;

2.If it is for MsAcess then

the above steps are same only the driver and class.forName changes ..
now i forget it later i will send it.

Pls try the above coding and reply is must.If it is wrong Pls send the correct answer...

bye takecare!

by
ela
Yuo should add the jar file in the class path(in the lib folder of your application). The error you are getting states that.
Jan 24 '08 #8
JosAH
11,448 Recognized Expert MVP
As a side note: I see everone going Class.forName(" your.driver") but doesn't anyone
use the more versatile DataSource method for obtaining (pooled) connections?
It's been here since Java 1.4. Read all about it in its API documentation ...

kind regards,

Jos
Jan 24 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4141
by: Jeff Sandler | last post by:
I have a database I created in mySQL. I've been entering data every day into the database using a Java application that I wrote. The database and the Java program are on the same Win 98 SE machine. I've been working on another program (an applet) to send and receive data over the internet. I got the applet to connect with the database and receive data. All the while I was developing the applet, I would tell it to find the database at...
0
1691
by: Mike Chirico | last post by:
I found the following interesting and wanted to pass it along Reference (TIP 12): http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download Connect and Select from Java // // mysql-connector-java-3.0.11-stable-bin.jar or later must be
30
7447
by: aka | last post by:
Hi I have a DB2 v8.1 on AIX and DB2 Connect EE on Solaris wich is connected to OS/390 DB2 subsystems via APPC / SNA. I have cataloged the DB2 Connect instance as tcpip node and then the Host DB cataloged on that node...this works from v7.2 Fixpack 11 clients and servers, but with v8.1 server I get SQL1334N. Does anyone has an idea? Thanks
11
10331
by: Mikael Arhelger | last post by:
Hello, This has been posted a few times but still I could not find a way to connect to our database. We run DB2 Express on WIN2K server with XP clients. I can ping inside network and to the Internet from the server, so TCP/IP is ok. The DB2COMM=TCPIP is set also. Have been scratching my head for days now. Here some additional data (we are running SAP Business One):
3
2912
by: arasub | last post by:
ep 20, 2007 11:25:57 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_12\bin;.;C:\WINDOWS\System32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin;C:\Program...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.