Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Java, UnixODBC and MySQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-03-08, 06:35
sindhu_sundar sindhu_sundar is offline
Registered User
 
Join Date: Jul 2008
Posts: 1
Question Java, UnixODBC and MySQL

Hello,

Am new to Java, UnixODBC and MYSQL. I need help with running a java program that connects to a mySQL DB and retrieves values.

I use Mandriva Linux, I installed UnixODBC (I have the GUI too), MySQL (I have SQLGUI too).

With the help of instructions from the unixodbc site I have been able to set up the driver for mysql in the odbcconfig and also successfully created the DataSouceName (DSN) as data1.

Now, my java program code is as follows...

Code:
import java.io.DataInputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; class employee_prg { @SuppressWarnings("deprecation") public static void main(String args[]) { try { DataInputStream in = new DataInputStream (System.in); System.out.println("Please enter employee number: "); String in_empno = in.readLine(); //database connectivity code Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); Connection con = DriverManager.getConnection("jdbc:odbc:myodbc;UID=root;PWD=<mypasshere>"); String empno = null; PreparedStatement ps = con.prepareStatement("Select * from employee where empid like '"+empno+" '"); ResultSet rs = ps.executeQuery(); if (rs.next()) { System.out.println(rs.getString(1)); System.out.println(rs.getString(2)); System.out.println(rs.getString(3)); } else System.out.println("No Record exists"); } catch (Exception e) {} } }

Since am new to java the language itself, I don't know if it is my code that is wrong or the procedure am following for db connectivity.

Using SQLGUI i created the "employee" table in the "test" database.
There are no values in that table because i do not know how to add.

[Can someone please direct me to a simple tutorial on this? for a quick learning in mySQL basics]

I decided to use mysql because the bridge for mdb files provided by easysoft.com is shareware.

please do suggest what is the best , mdb or mysql db for my java program.

am looking forward for help on the java code i pasted. thanks
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On