My question is :
1. can I access directly in database online?
2. And if yes , what is the information needed to access?
3. how to write code because I write this code always the output is errors.
import java.sql.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.Image;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class SelectQuery extends JPanel
{
private Connection con=null;
private Statement selectStatement;
private ResultSet selectResult;
private String annotation;
private Scanner scan;
private BufferedImage bImage;
public void connectToDB()
{
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};" +
"Dbq=//arab-dreamers.com/home/arabdrea/KeyPicDB.accdb";
System.out.println(url);
try{
System.out.println("Loading the driver ...");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to database ...");
// con = DriverManager.getConnection(url,"arabdrea","0569545844");
con = DriverManager.getConnection(url,"","");
if(con!=null)
System.out.println("Connected to database ...");
}
catch(SQLException sqle)
{
System.out.println(sqle.getMessage());
System.exit(1);
}
catch(ClassNotFoundException cnfe)
{
System.out.println(cnfe.getMessage());
}
}//=================================================
public void closeDB()
{
try {
if(con != null)
con.close();
}
catch(SQLException sqle)
{
System.out.println(sqle.getMessage());
}
}//===============================================
public void Query()
{
String anno="street";
String query = "SELECT * FROM Table1 WHERE Annotation='"+anno+"'";
try{
selectStatement = con.createStatement();
System.out.println("Sending Query to database Table ...\n");
selectResult = selectStatement.executeQuery(query);
System.out.println("The Query : "+query+"\n");
System.out.println("Query results\n");
while(selectResult.next())
{
System.out.println("idn="+selectResult.getString("ID"));
}//while
selectResult.close();
}//try
catch(SQLException sqle)
{
System.out.println(sqle.getMessage());
}
}//=============================================
public static void main(String[] args)
{
SelectQuery sq = new SelectQuery();
sq.connectToDB();
// sq.Query();
sq.closeDB();
System.out.println("Ooo");
}
}//class
Please help me quickly.

New Topic/Question
Reply




MultiQuote




|