473,424 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,424 software developers and data experts.

How to create a database with java

Hi everyone,

So ive basically searched the interwebs and tried some examples but i cant not seem to get this working. I would like to create a Java program in which i can save data into a database. The GUI part is not the problem, the problem is getting Java to communicate with MySQL. I have no idea how to establish a connection bewteen my Java program and MySQL.
I have downloaded and installed wampserver 2.0 and i am pretty much lost after this point. Does anyone know of any good reading material that can help me out with this? maybe provide a small example?

thanks a million!
Jul 6 '10 #1
1 1231
use jdbc odbc connection to connect to databases, may it be MySQL or MS Access or any other.
Example: here emp table contains name & sal


Expand|Select|Wrap|Line Numbers
  1. import java.sql*;
  2.  
  3. class JdbcDemo 
  4. {
  5.     public static void main(String[] args) 
  6.     {
  7.         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  8.         Connection con = DriverManager.getConnection("jdbc:odbc:ooo", "" , "");
  9.         Statement st = con.createStatement();
  10.         Resultset rs = st.executeQuery("select * from emp");
  11.         while(re.next())
  12.         {
  13.             System.out.println(rs.getString(1) + "\t" + rs.getInt(2));
  14.         }
  15.         con.close();
  16.  
  17.  
  18.     }
  19. }
  20.  
Jul 12 '10 #2

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

Similar topics

3
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with...
0
by: Mary Lei | last post by:
After instaling db2 8.2.2 on a solaris box I ran a script that drops a database and then creates it. This scripts runs fine under db2 8.2.1 on linux. With 8.2.2 I got a mysterious error about...
3
by: Erik Thorsen | last post by:
Hello! I am in the process of creating a database listing tours, something similar to what you can find on www.infohub.com. This means that I need to create a database which can be searchable...
6
by: di | last post by:
Does anyone have any recommendations on Examples or experience on creating a multilevel commission in Access Database. I realize this can be a very complicated set up so would like some advise....
2
by: Robin | last post by:
When I try to create a new database, I receive the following error: " ADO error:' SQL Server does not exist or access denied " Any sugguestions??
3
by: Dave | last post by:
I've run across a strange error when creating a simple ADO.Net connection in VB.Net 2003 To replicate an error: Create an Access database (2002) with table named "Student" and fields SID...
1
by: ROO | last post by:
Hi Everyone, I need some help Creating Database Connection at runtime and writing Connection String to App.Config, I have 3mxtboxes on a form txtUsername = SQL admin User txtPassword = Sql admin...
2
by: sreek518 | last post by:
hi, anyone have ideas regarding how to create a java IDE. can u pls specify the steps involved in creating the IDE, also with links where I can get necessary information. ( actually we are final...
0
by: danielmessick | last post by:
Hey all !! I'm having a frustrating time trying to create a particular Java applet for a class.. I have no clue how to accomplish this, and really need HELP.. Anyone, PLEASE help me if you can, any...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.