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.(test.java:14)
at test.main(test.java:23)
pls help me to solve this.....
View Answers
March 23, 2012 at 11:39 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);
}
}
}
Ads
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
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 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
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
Using Network Address To Connect to a Database
to
connect a MySql
database with your application over a
network then you must load... is "root"
An example of using network address to
connect to
database...
.style1 {
text-align: center;
}
How To Use Network Address To
Connect
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