2 Replies - 1326 Views - Last Post: 30 September 2011 - 08:55 AM Rate Topic: ***-- 2 Votes

#1 Mandrake1942  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-April 09

Java application / widget for windows xp

Posted 30 September 2011 - 02:18 AM

Hello guys

My idea is to build an application/widget for windows that can connect to a database(oracle or access) retrieve data and show it.
Unfortunately i got stuck at connecting to the company database
import java.sql.*;
public class Test
{
 public static void main(String[] args) 
 {
 String dataSourceName = "HULL_DWG_STATUS";
 String dbURL = "jdbc:odbc:" + dataSourceName;
 try { 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, "alexandra","pass"); 
}
 catch (Exception err) {
System.out.println( "Error: " + err );
 }
 }
}

ai use this code to connect but i get an error that is used by another person but i can connect to it from Access.Could you please give me a solutin? Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Java application / widget for windows xp

#2 Mandrake1942  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-April 09

Re: Java application / widget for windows xp

Posted 30 September 2011 - 03:16 AM

Sorry for triple post my internet connection at work is really crap.I can't find the edit button to delete the threds must be this shitty version of internet explorer 4 or 5.A moderator should delete them.Thanks
Was This Post Helpful? 0
  • +
  • -

#3 burakaltr  Icon User is offline

  • D.I.C Regular

Reputation: 91
  • View blog
  • Posts: 280
  • Joined: 07-November 10

Re: Java application / widget for windows xp

Posted 30 September 2011 - 08:55 AM

ıf it were a MYSQL database, after what is told on internet sites ( where to locate the jdbc driver and set PATH, etc. ) The following code worked fine for me ( Operating on WAMP )

Maybe it will be of use to you

package snippet;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class main{
  public static void main(String[] args) throws Throwable {
  System.out.println("MySQL Connect Example.");
 Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "db_0";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"; 
  String password = "";
  try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  System.out.println("Connected to the database");
 // conn.close();
  //System.out.println("Disconnected from database");
  } catch (Exception e) {
  e.printStackTrace();
  }
  String[] country = new String[40000];
  String[] city = new String[40000];
   PreparedStatement stmt=conn.prepareStatement("select * from city");
   
   ResultSet rs=stmt.executeQuery();
   int z = 0;
   while(rs.next()){
	  
	city[z]=rs.getString(2);
	z++;
	//   System.out.println(rs.getString(1)); 

			   }
 ;
   
   conn = DriverManager.getConnection(url+dbName,userName,password);
   PreparedStatement stmt2=conn.prepareStatement
		   ("select * from country");
   
   ResultSet rs2=stmt2.executeQuery();
   int j=0;
   while(rs2.next()){
   
country[j]=rs2.getString(1);
j++;
 //  System.out.println(rs2.getString(1)); 
   }
   System.out.println(city.length);
//for(int i=0;i<z;i++) {
	

	//System.out.println(city[i]);


for(int i=0;i<j;i++) {
	

	System.out.println(city[i]+" "+country[i]);

}



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1