access to database

how to access database online

Page 1 of 1

7 Replies - 931 Views - Last Post: 19 June 2009 - 05:44 AM Rate Topic: -----

#1 raqi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 13-November 08

access to database

Posted 18 June 2009 - 03:14 AM

I design program that the user can enter text and from this text you can add pictures by searching for annotated images in the web.
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.

Is This A Good Question/Topic? 0
  • +

Replies To: access to database

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: access to database

Posted 18 June 2009 - 07:16 AM

1. If the database is configured to accept such connections then yes -- however it is not common for databases to be configured this way (because it is a HUGE security risk) -- generally there is some proxy that limits what can be accomplished.

2. This would depend upon the database. There are various formats for the database connection strings.

3. Generally you would use JDBC to connect to a database.
Was This Post Helpful? 0
  • +
  • -

#3 raqi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 13-November 08

Re: access to database

Posted 18 June 2009 - 04:18 PM

how to configured the DB to accept the connection?? and what does he mean about the proxy??
what is the difference between the database connection strings?? i..e how can we choose the appropriate database connection strings for our DB??
Was This Post Helpful? 0
  • +
  • -

#4 raqi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 13-November 08

Re: access to database

Post icon  Posted 18 June 2009 - 05:14 PM

I want to access to database in special site not in common web
this is all avliable information :

- address of the site (www. ).
- database Name: KeyPicDB.accdb.
- database type: Access.
- Shared Ip Address.
- user name & password for site's control panel not for database.
- Server Name .
- database place in the Server .
- URL of database .
- DNS.

1. Connection String ?? i don't know
2. is this enough or not in java?
3. how to configured the database to accept the connection??
4. whats the difference between the database connection strings?? i..e how can we choose the appropriate database connection strings for my database??
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: access to database

Posted 18 June 2009 - 05:33 PM

Yu are doing that from an application or an Applet ?
If it is from an Applet, you just can't

and BTW
[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: access to database

Posted 18 June 2009 - 07:50 PM

Topics merged...

So basically it looks like you are working on a client/server type of structure where a client application connects to a server application. This is where JavaEE comes in.

Generally the way this is done is you have a program running a server and this program interacts with the DB is a controlled manner (you really don't want to open up a DB to the internet as it would be completely unsecure). So the client talk so the server program which runs your queries and interacts with the database -- the server then sends the results back to the client.

BTW -- Access is not really a great DB for Java (sure it works -- but there a ton of better choices).
Was This Post Helpful? 0
  • +
  • -

#7 raqi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 13-November 08

Re: access to database

Posted 19 June 2009 - 02:28 AM

my code above in the first mail please help me and I don't know what is the prblem

NickDMax: wt does he mean abt the proxy??
pbl: my program is application?

i'm sorry for late because different time btween you
Was This Post Helpful? 0
  • +
  • -

#8 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: access to database

Posted 19 June 2009 - 05:44 AM

What I meant by a proxy is some application that sits between the client and the database. The client makes requests to this application which then forwards the request to the DB and forwards the result on to the client. This way you can control what the client does -- for example you can ensure that the client never runs a sql query like, "DROP TABLE X".


Though one question: When you say "internet" do you actually mean "network" -- because using a DB on a network is completely common and does NOT require a proxy (so long as your network is secured anyway).

Take a look at this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1