unable to connect database in java

unable to connect database in java

Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code.

try
      {
       Driver d=(Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
         c=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=E:/Final Project/Lalit.mdb");

         st=c.createStatement();

        }catch(Exception e){e.printStackTrace();}

And i am getting this error

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not fou
nd and no default driver specified
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
        at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
        at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)
        at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
23)
        at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
        at java.sql.DriverManager.getConnection(DriverManager.java:579)
        at java.sql.DriverManager.getConnection(DriverManager.java:243)
        at test.<init>(test.java:14)
        at test.main(test.java:23)

pls help me to solve this.

View Answers

March 23, 2012 at 11:40 AM

Follow these steps:

1)Go to the start->Control Panel->Administrative Tools-> data sources.

2)Click Add button and select the driver Microsoft Access Driver(*.mdb).

3)After selecting the driver, click finish button.

4)Then give Data Source Name and click ok button.

5)Your DSN will get created.

6) Restart your compiler and compile your java code.

For Inserting Data:

import java.sql.*;
class AccessDatabase{
    public static void main(String[] args){
        try{
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
           Statement st=con.createStatement();
           String name="roseindia";
           String address="delhi";
           int i=st.executeUpdate("insert into user(name,address) values('"+name+"','"+address+"')");
           System.out.println("Row is added");
           }
        catch(Exception e){
            System.out.println(e);
        }
    }
}









Related Tutorials/Questions & Answers:
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code.... try { Driver d=(Driver)Class.forName
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... created. 6) Restart your compiler and compile your java code. For Inserting Data
Advertisements
java script unable to connect to oracle database and insert data
java script unable to connect to oracle database and insert data  ... is to insert data from jsp to oracle database 8, so i create a table in oracle... org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data..
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data.... If I use it also, unable to connect to backend oracle database. Let me... for the connection to the database is specified in the Web-inf >> config
Connect to the database
Connect to the database  how to connect to the database in the iphone
unable to connect to server - JSP-Servlet
unable to connect to server  thank you for the program code for inserting and reteriving the image but i am unable to deploy these two programs in weblogic/apache servers can any one help me how to do this ?   Hi Friend
TO connect multiple database
TO connect multiple database  How to connect several database from a single application in java depending upon the user input it will connect to that database
Unable to store the image into database
Unable to store the image into database  Hello, I have created below program and program is throwing FileNotFound exception when I pressed the submit...); }   Hi, Please check the thread How to Insert image into database
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
connect database without specifying dsn name in java
connect database without specifying dsn name in java  How can i connect the database with my application without specifying the dsn name by using jdbc & odbc..... i have saw this code on the web-site try
connect a web page to a database
connect a web page to a database  how to connect a web page to a database
connect database with javascript
connect database with javascript  can you please tell me how to connect database with javascript code. [email protected] this is my mail id thanks in advance
connect to the database from JSP
connect to the database from JSP  How do you connect to the database from JSP?   A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets
Connect database in Access to Netbean?
Connect database in Access to Netbean?  how to connect database in micrsoft access to Netbean?i know it can be connected by using JDBC-ODBC bridge, can i know the steps in connecting the database? Is there any source code
cannot connect to database - JDBC
cannot connect to database  Iam using eclipse in my system ,when connecting the database mysql version 5.0 to the eclipse iam getting an error as ""Creating connection to mysql has encountered a problem.Could not connect to mysql
How to connect with database
How to connect with database  jdbc connection
connect with Database - SQL
connect with Database  Hi, when ever i m trying to connect with 10g... problem with java 2 v1.4 with oracle 10g. But it worked well with the same code with java 5.0 with 10g. I am not sure whether it is technically correct answer
how to connect program to database
how to connect program to database  Sir i want ur help in my program. I want to save the data in the database. When i'll click on save button the entered data must be save in the database. I want an action performed method
unable to get datas from oracle database
unable to get datas from oracle database  Dear Sir, I am again struck in my project.. i want to display data from oracle database but i get... org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred
Unable to upload a file to mysql database using struts1
Unable to upload a file to mysql database using struts1  Hi, Below are my classes 1.upload.jsp <%@ taglib uri="/tags/struts-html" prefix="html" %> <html:html> <body> <html:form action="upload" enctype
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?  HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE
how to connect to database in php using mysql
how to connect to database in php using mysql  how to connect to database in php using mysql
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?  HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE
How to connect to the database to my application if my database is made up in oracle
How to connect to the database to my application if my database is made up in oracle   How to connect to the database to my application if my database is made up in oracle
what is ment by jdbc and how to connect with database?
what is ment by jdbc and how to connect with database?  i want answer for this question
Unable the get SubFolder Direcotry in Java?:-
Unable the get SubFolder Direcotry in Java?:-   Unable the get SubFolder Direcotry in Java?:- try { String st1 = "C:\TestFolder; // Main Folder URL File folder = new File(st1); File[] listOfFiles = folder.listFiles(); for (File
Using Network Address To Connect to a Database
to connect a MySql database with your application over a network then you must load... .style1 { text-align: center; } How To Use Network Address To Connect To The Database If a database being connecte over a network then you need to get
How to connect to database to my application if the database is made up in oracle
How to connect to database to my application if the database is made up in oracle  How to connect to database to my application if the database...) Connect to database:***ADS_TO_REPLACE_3 a) If you are using oracle oci driver
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
How To Connect MS ACCESS 2003 Database in C Program with Graphics.
How To Connect MS ACCESS 2003 Database in C Program with Graphics.  How To Connect MS ACCESS 2003 Database in C Program with Graphics
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
i can not connect to database in servlet - JSP-Servlet
i can not connect to database in servlet  Hi I am following... offer .   Hi friend, Code to connect to database in servlet... to a databse by a servlet.I used the example in "Inserting Data In Database
i can not connect to database in servlet - JSP-Servlet
i can not connect to database in servlet  Hi I am following... offer .   Hi friend, Code to connect to database in servlet... to a databse by a servlet.I used the example in "Inserting Data In Database
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  //this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  //this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
How can I connect my database to my application ?
How can I connect my database to my application ?  How can I connect my database to my application?   Hi, You can use JDBC API to connect to database from your Java application.ADS_TO_REPLACE_1 Here is the sample
how to connect to MS access database in JSP?
how to connect to MS access database in JSP?  how to connect to MS access database in JSP? Any seetings/drivers need to be set or installed before it? Please tell what needs to be done after creating a table with an example
use properties file to connect to the database in jsp..
use properties file to connect to the database in jsp..  How to use properties file to connect jsp code with database ..........   Here is a jsp code that connects to database using properties file. <%@page import
pls provide steps to connect mysql database in flex - XML
pls provide steps to connect mysql database in flex  hi,i am new to flex and doing project. i have doubt in how to connect MYSQL database in flex .pls provide the steps . i would be really thankful 2 u. i am loooking
Java Connect to and FTP Server
Java Connect to and FTP Server  What is the code for Java Connect to and FTP Server? How to establish a connection to FTP server in Java? Thansk... the apache commons library to connect/login to FTP server. Link of complete example
how to connect the database using hibernet through servlet/jsp through form
how to connect the database using hibernet through servlet/jsp through form  plz give me the reply   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/jsf/myfacesspring
pls provide steps to connect mysql database in flex - XML
pls provide steps to connect mysql database in flex  hi, pls provide steps to connect mysql database in flex.pls i am trying from last week still it was not connected .pls provide the step by step procedure.i am looking
How to connect to MySql Database from Servlet?
; font-weight: bold; } How to connect to MySql Database from Servlet... will show you how to connect to MySQL database and perform select operation. You will learn the JDBC steps necessary to connect to the MySQL Database and execute
Unable looping using JOptionPane - Java Beginners
Unable looping using JOptionPane  import javax.swing.*; public class Shop{ public static void main(String [] args){ Shop shop = new Shop(); String mainMenu= "(MAIN SCREEN )"; mainMenu+= "\n1) Computer Menu

Ads