Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
ODBC problem

 
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum
Author Message
Fahad
Beginner User
Beginner User


Joined: 16 Mar 2004
Posts: 16

Post Post subject: ODBC problem Reply with quote

Hi everyone!

How are you all. Sorry I was busy for sometimes and couldn't come to the forum.

Mr. belal, in java when we write a java application that has a link with database, we often do it with odbc connection. to make the program run, we have to first make the odbc connection (from control pannel). it is little bit disturbing. Can't I write code that will create odbc connection before running the application? Pls, help me with some code.

Fahad
Tue May 18, 04 2:38 pm
Back to top
Fahad View user's profile Send private message Yahoo Messenger
Mastermind
Expert User
Expert User


Joined: 23 Apr 2004
Posts: 181
Location: Birmingham,UK

Post Post subject: Reply with quote

I'm not exactly sure what you are trying to say but I connect to MySQL database from java using the following code

Code:
public void createDatabase(String DBName) throws Exception {                 
  Connection conn;
  Statement st=null;
  ResultSet rs=null;
  Class.forName("com.mysql.jdbc.Driver");
  conn = DriverManager.getConnection("jdbc:mysql://localhost/ttdatabase");
  st = conn.createStatement();



I guess it should be similar with the ODBC as well.
_________________
Keep your own dignity, both online and offline throughout your life !!!
Thu May 20, 04 4:34 am
Back to top
Mastermind View user's profile Send private message
Belal
User
User


Joined: 08 Mar 2004
Posts: 84
Location: Dhaka, Bangladesh

Post Post subject: Reply with quote

hi fahad, it's good to see post frm u after a long time. yes, mastermind is right..............ur odbc connection way sould b similar. but here i m also giving u a code that does it (database: ms access)

import java.sql.*;
import java.io.*;

public class DatabaseConnection
{

//__________Declare Global Objects________
Connection con;
Statement stmt;

public DatabaseConnection()
{
File f1=new File("myDB.mdb");
try
{
//__________Loading Driver__________
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//__________Creating Connection___________
Connection con= DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};" +"DBQ="+f1.getAbsolutePath()+"","Administrator","");

//_________Creating Statement___________
stmt=conOthers.createStatement();
}catch(ClassNotFoundException cnfe){System.out.println("Class Not Found Error!!!");}
catch(SQLException sqle){ System.out.println("SQL Exception found!");}
}//End of constructor
}//End of class DatabaseConnection

in fact, this class file solve two prob:
1. connecting to ur db
2. connecting to a db that is in ur working folder

let me know if it doesn't solve ur prob
_________________
we've lot of things to think abt curr probs
so, i don't have time to think abt religion or wonder of sceice .......... how ppl can waste their time like this?
Thu May 20, 04 10:22 am
Back to top
Belal View user's profile Send private message Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group