The Mystery of Connecting to an Access Database
I am just starting to use designer and with some stumbles along the way have perfected the layout of the form I am trying to create. The next step is connecting it to a Microsoft Access database. However, I am having some problems.
I have looked everywhere imaginable for a "how-to" on connecting an Access database to my form in Designer. I have gone through setting up data connections several times, all with the same result: "Connection for Source NPIF failed because the environment is not trusted". NPIF is the name of the data connection I've been trying to set up.
I realize this is probably a very boring problem to solve, but I am desperate! I have not seen any answers to other posts asking this same question, so I'm worried this one will be overlooked too. Please, there are many of us out there who cannot figure this out! Help us?
Other people seem to have set this up with no problems. Maybe one of you can post the steps you took to get it to work - share the love!!
Thank you, Elizabeth
Chris, here's my script. It's in the initialize event.<br /><br />----- ProjectInformationForm.Page1ClientBillingProject.Client.DataDropDownList::initialize - (JavaScript, client) <br /><br />/* This dropdown list object will populate two columns with data from a data connection.<br /><br /> sDataConnectionName - name of the data connection to get the data from. Note the data connection will appear in the Data View.<br /> sColHiddenValue - this is the hidden value column of the dropdown. Specify the table column name used for populating.<br /> sColDisplayText - this is the display text column of the dropdown. Specify the table column name used for populating.<br /><br /> These variables must be assigned for this script to run correctly. Replace <value> with the correct value.<br />*/ <br /><br />var sDataConnectionName = "NPIF"; // example - var sDataConnectionName = "MyDataConnection";<br />var sColHiddenValue = "ClientName"; // example - var sColHiddenValue = "MyIndexValue";<br />var sColDisplayText = "ClientName"; // example - var sColDisplayText = "MyDescription"<br /><br />// Search for sourceSet node which matchs the DataConnection name<br />var nIndex = 0;<br />while(xfa.sourceSet.nodes.item(nIndex).name != sDataConnectionName)<br />{<br /> nIndex++;<br />}<br /><br />var oDB = xfa.sourceSet.nodes.item(nIndex);<br />oDB.open();<br />oDB.first();<br /><br />// Search node with the class name "command"<br />var nDBIndex = 0;<br />while(oDB.nodes.item(nDBIndex).className != "command")<br />{<br /> nDBIndex++;<br />}<br /><br />// Backup the original settings before assigning BOF and EOF to stay<br />var sBOFBackup = oDB.nodes.item(nDBIndex).query.recordSet.getAttribute("bofAction");<br />var sEOFBackup = oDB.nodes.item(nDBIndex).query.recordSet.getAttribute("eofAction");<br /><br />oDB.nodes.item(nDBIndex).query.recordSet.setAttribute("stayBOF", "bofAction");<br />oDB.nodes.item(nDBIndex).query.recordSet.setAttribute("stayEOF", "eofAction");<br /><br />// Clear the list<br />this.clearItems();<br /><br />// Search for the record node with the matching Data Connection name<br />nIndex = 0;<br />while(xfa.record.nodes.item(nIndex).name != sDataConnectionName)<br />{<br /> nIndex++;<br />}<br />var oRecord = xfa.record.nodes.item(nIndex);<br /><br />// Find the value node<br />var oValueNode = null;<br />var oTextNode = null;<br />for(var nColIndex = 0; nColIndex < oRecord.nodes.length; nColIndex++)<br />{<br /> if(oRecord.nodes.item(nColIndex).name == sColHiddenValue)<br /> {<br /> oValueNode = oRecord.nodes.item(nColIndex);<br /> }<br /> else if(oRecord.nodes.item(nColIndex).name == sColDisplayText)<br /> {<br /> oTextNode = oRecord.nodes.item(nColIndex);<br /> }<br />}<br /><br />while(!oDB.isEOF())<br />{<br /> this.addItem(oTextNode.value, oValueNode.value);<br /> oDB.next();<br />}<br /><br />// Restore the original settings<br />oDB.nodes.item(nDBIndex).query.recordSet.setAttribute(sBOFBackup, "bofAction");<br />oDB.nodes.item(nDBIndex).query.recordSet.setAttribute(sEOFBackup, "eofAction");<br /><br />// Close connection<br />oDB.close();
Similar Messages
-
Using JSP to connect to an Access Database
I need help on using JSP to connect to an Access database.
This is the code I currently have connecting to a mySQL DB. I need to change it to connect to an Access DB. The reason I am switching DB's is because mySQL is no longer going to be carried by my host.
Here is the code:
<html>
<head>
<basefont face="Arial">
</head>
<body>
<%@ page language="java" import="java.sql.*" %>
<%!
// define variables
String UId;
String FName;
String LName;
// define database parameters
String host="localhost";
String user="us867";
String pass="jsf84d";
String db="db876";
String conn;
%>
<table border="2" cellspacing="2" cellpadding="5">
<tr>
<td><b>Owner</b></td>
<td><b>First name</b></td>
<td><b>Last name</b></td>
</tr>
<%
Class.forName("org.gjt.mm.mysql.Driver");
// create connection string
conn = "jdbc:mysql://" + host + "/" + db + "?user=" + user + "&password=" +
pass;
// pass database parameters to JDBC driver
Connection Conn = DriverManager.getConnection(conn);
// query statement
Statement SQLStatement = Conn.createStatement();
// generate query
String Query = "SELECT uid, fname, lname FROM abook";
// get result
ResultSet SQLResult = SQLStatement.executeQuery(Query);
while(SQLResult.next())
UId = SQLResult.getString("uid");
FName = SQLResult.getString("fname");
LName = SQLResult.getString("lname");
out.println("<tr><td>" + UId + "</td><td>" + FName + "</td><td>" + LName
+ "</td></tr>");
// close connection
SQLResult.close();
SQLStatement.close();
Conn.close();
%>
</table>
</body>
</html>
Thank You,
Josh<%@ page language="java"%>
<html>
<head>
<title>
First Bean
</title>
<%@ page import="java.sql.*" %>
</head>
<body>
<p>
<%!
Connection con;
Statement st;
ResultSet rs;
String userid;
String password;
%>
<%!public void db(JspWriter out)
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:phani");
catch(Exception e){}
try{
st=con.createStatement();
rs=st.executeQuery("SELECT * FROM login");
while(rs.next())
userid=rs.getString("userid");
password=rs.getString("password");
out.println(userid);
out.println("</br>");
out.println(password);
out.println("</br>");
}catch(Exception e){}
try{
con.close();
}catch(Exception e){}
%>
<%db(out);%>
</p>
</body>
</html>
phani is dsn name
login is table name
Good luck
phani -
Connecting to an access database
I am trying to connect to an access database using asp.net
vb.
I am getting a "unidentified error".
Any suggestions?1. Post code for how you're connecting
2. Post procedure you went through to get that code
"sabafana" <[email protected]> wrote in
message
news:e4krqh$h07$[email protected]..
>I am trying to connect to an access database using
asp.net vb.
> I am getting a "unidentified error".
> Any suggestions? -
Breaking the Sharepoint connection within an Access database
We have recently changed our online database to a new system. We downloaded all the current information into excel or access. However my major database to track all staff training, mandatory renewables and policy reviews will not allow attachments to be
uploaded to the access database because "the sharepoint table is no longer available". We have had many problems with sharepoint, and wish to convert the database strictly to access and break the sharepoint connection to the former website. Is there
a way to do this?
Please adviseHi
This is the forum to discuss questions about Access develop. For your question is SharePoint related, I am moving this thread to the SharePoint forum
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share
their knowledge or learn from your interaction with us.
Thank you for your understanding.
Best Regards
Lan
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
DW Procedures to connect to MS ACCESS database located on remote server
I am confused about the procedures within Dreamweaver CS3 to connect to a MS ACCESS database on a remoter server.
I am working through a tutorial book, "Dreamweaver 8 with ASP, Cold Fusion and PHP Training from the Source", but the instructions are unclear concerning the procedures to connect to a MS ACCESS database located on a remote server.
The book indicates that the server administration has to create the DSN for you and screen shots indicate that you will result in a list of DSNs to choose from when creating the connections .asp file.
I went through the procedures to create a connections .asp and resulting in a connection without and tables (of course) because I do not initially have any connection information from my remote site.
I have generated the required two lines of code as follows for my MS ACCESS database connection on my remote server:
'Database connection info and provider
strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&_
Server.MapPath("database\trans.mdb") & ";" &_
"User ID=xxx;Password=xxxxx"
The question that I have is:
How does this connection coding relate to the "connections/conn_newland.asp" file that was create within the Dreamweaver screens? How do I merge the ASP coding? The file (/connections/conn_newland.asp) generated within Dreamweaver is as follows:
<%
'FileName="Connection_odbc_conn_dsn.htm"
'Type="ADO"
'DesignationType="ADO"
'HTTP="true"
'Catelog=" "
'Schema
Dim MM_conn_newland_STRING
MM_conn_newland_STRINT = "dsn=newland;"
%>
Any advice would be appreciated. I know that this is simple but debugging an error from an ASP coding merge would be a "bear" to debug!I have not used MS Access myself (fortunately) but I believe it works much like the old, old way of achieving a multi-user database in FileMaker.
That is, it is not a true client-server database but more a peer-to-peer database and that each peer opens the same database file which is available to multiple user via file sharing. Therefore as elikness said it should just be a matter of putting the files on your Lion Server and then sharing that folder/volume using SMB sharing.
However one thing to be aware of, since MS Access is not a true client-server database I would imagine it uses record locking to manage simultaneous direct access to records in the same files. File or Record locking is something that has historically been a bit flakey when using Windows clients with a Mac file server (and probably vice versa).
While I am not proposing it as a solution to consider seriously, it is worth you knowing that FileMaker Pro is a database system that is available for both Mac and Windows and depending on how you configure things can be considered to stretch from a configuration very similar to MS Access at the low end all the way to a high-end MS SQL Server style setup at the top end. See http://www.filemaker.com for details.
There is also a a third-party tool available for migrating databases to or from FileMaker Pro and it can convert MS Access databases to FileMaker Pro see http://www.fmpromigrator.com/
You could use FileMaker Pro just on Windows machines if you wish. -
Getting the table names in an MS Access database
Hi,
I am new to JDBC and making a client/server application that updates a MS Access database through jdbc:odbc.
I need to get a list of existing user tables in the db. I have found a great document on the net which has the code, however the code doesn't work. I have tried different ways and looked every where with no success. (link to the doco: http://www-128.ibm.com/developerworks/opensource/library/j-jdbc-objects/)
Here is my dbManager class that handles all db related services in my application. I would appreciate any help I can get as I have exhusted all my avenues.
Thanks
Sep,
* dbManager.java
* Created on 31 October 2005, 10:20
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
import java.io.*;
import java.sql.*;
import java.util.regex.*;
* @author AUMahdavSe
public class dbManager {
/** Constant Declaration */
public static final String Driver = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final
String sqlCreateTable = "create table TABLENAME (" +
"name varchar (100)," +
"surname varchar(100)," +
"computerType integer," +
"computerNAL varchar(20)," +
"haveMonitor integer," +
"monitorNAL varchar (20)," +
"auditDate varchar(10) );";
public static final String sqlUpdateTable = "insert into TABLENAME values" +
" (NAMEHOLDER, SURNAMEHOLDER, COMPTYPE, COMPNAL, HAVEMON, MONNAL);";
/** Attributes */
private String dbURL = "jdbc:odbc:";
private String Username = "admin"; // user input
private String Password = "purina123"; // user input
private String ODBCDataSource; // config file
private String dbPath; // set through config file or defaults to current folder
private String configFile = "config.txt"; // set either at commandline or defaults to current folder
private Connection con = null;
private Statement stmt = null;
private ResultSet tables;
private DatabaseMetaData dma;
private ResultSetMetaData rsmd;
private String CurrentAuditTable = "TestTable2";
int numCols, i;
/** Set Methodes */
public void setUsername( String usr ) {
this.Username = usr;
public void setPassword( String pswd ) {
this.Password = pswd;
public void setDbPath( String path ) {
this.dbPath = path;
public void setODBCDataSource( String ds ) {
this.ODBCDataSource = ds;
public void setDbURL( String dsname ) {
this.dbURL = this.dbURL + dsname;
/** Get Methodes */
public String getDriver() {
return this.Driver;
// can be run only after a connection obj is setup
public void getMDA() {
try {
this.dma = this.con.getMetaData();
catch (SQLException ex) {
System.err.println("database connection: " + ex.getMessage());
public void getDBTables() {
//now dump out the names of the tables in the database
String[] types = new String[1];
types[0] = "TABLES"; //set table type mask
//note the %-sign is a wild card (not '*')
try {
this.tables = this.dma.getTables(null, null, "%", types);
dumpResults("--Tables--");
this.tables.close();
//this.listTables();
catch (SQLException ex) {
System.err.println("database connection: " + ex.getMessage());
// listing tables
/*int count = 0;
int numCols = 0;
//ResultSetMetaData rsmd;
try {
System.out.println("Listing db tables ...");
//this.tables.beforeFirst();
rsmd = this.tables.getMetaData();
numCols = rsmd.getColumnCount();
System.out.println("number of cols: " + numCols);
boolean more = this.tables.first();
System.out.println("this is why: " + more);
while ( more ) {
count++;
for (int i = 1; i <= numCols; i++)
System.out.print( "Table-" + count + " -> " + this.tables.getString(count)+" " );
System.out.println();
more = this.tables.next();
catch ( SQLException ex ) {
System.out.println( "problem listing db tables: " + ex.getMessage() );
/** Other Methodes */
// Initialize the db parameters, like driver, username, passwd, etc.
public void dbInitialize() {
// load configuration from config.txt (dbPath and ODBC Data Source name)
this.loadDbConfig();
// loadDriver
this.loadDriver();
// get username and password for the ODBC from user
this.getDSSecurity();
// populate dbURL, username and password
this.setDbURL( this.ODBCDataSource );
// connect to db
this.dbConnect();
// get db metadata
this.getMDA();
// get a list of tables in db
this.getDBTables();
// load JDBC driver
public void loadDriver() {
try {
Class.forName( getDriver() );
} catch (Exception e) {
System.out.println("Failed to load JDBC/ODBC driver.");
return;
// connects to db and create a Connection obj and a Statement obj
public void dbConnect() {
try {
this.con = DriverManager.getConnection (
this.dbURL,
this.Username,
this.Password);
this.stmt = con.createStatement();
} catch (Exception e) {
System.err.println("problems connecting to "+this.dbURL);
// creates table tblname in db
public void CreateTable( String tblname ) {
try {
String sqlcommand = mergeTblName(sqlCreateTable, tblname);
this.stmt.execute( sqlcommand );
catch (SQLException ex) {
System.err.println("problems with SQL statement sent to "+this.dbURL+
": "+ex.getMessage());
System.out.println("SQL Command: " + mergeTblName(sqlCreateTable, tblname) );
// updates db with new record(s) by executing the SQL query sqlstmt
// and closes db connection
public void dbUpdate( String sqlstmt ) {
try {
// execute SQL commands to create table, insert data
this.stmt.execute( sqlstmt );
this.con.close();
} catch (Exception e) {
System.err.println("problems with SQL sent to "+this.dbURL+
": "+e.getMessage());
// list all user tables in the db
public void listTables() {
//now dump out the names of the tables in the database
int count = 0;
try {
System.out.println("Listing db tables ...");
//this.tables.beforeFirst();
while ( this.tables.next() ) {
count++;
System.out.print( "Table-" + count + " -> " + this.tables.getString(1) );
System.out.println();
catch ( SQLException ex ) {
System.out.println( "problem listing db tables: " + ex.getMessage() );
// checks whether tbname exist in db as a table
// this function has to be called after dbConnect
public boolean tableExists( String tbname ) {
boolean tbexists = false;
//get the database metadata
try {
dma = con.getMetaData();
catch (SQLException ex) {
System.err.println("database connection: " + ex.getMessage());
//now dump out the names of the tables in the database
String[] types = new String[1];
types[0] = "TABLES"; //set table type mask
//note the %-sign is a wild card (not '*')
try {
tables = dma.getTables(null, null, "%", types);
catch (SQLException ex) {
System.err.println("database connection: " + ex.getMessage());
try {
while ( tables.next() ) {
if ( tbname.equalsIgnoreCase( tables.getString(1) ) ) {
tbexists = true;
catch ( SQLException ex ) {
System.err.println("database connection: " + ex.getMessage());
return tbexists;
// merge tablename using REGEX
public String mergeTblName( String sqlcommand, String tbname ) {
String REGEX = "TABLENAME";
String INPUT = sqlcommand;
String REPLACE = tbname;
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(INPUT); // get a matcher object
INPUT = m.replaceAll(REPLACE);
//System.out.println(INPUT);
return INPUT;
// merge feildnames specific terms using REGEX
public String mergeFldName( Message msg ) {
String sqlcommand;
sqlcommand = "insert into TABLENAME values" +
" ('" + msg.getName() + "', '" + msg.getSurname() + "', " +
msg.getComputerType() + ", '" + msg.getComputerNAL() + "', " +
msg.getHaveMonitor() + ", '" + msg.getMonitorNAL() + "', '" +
msg.getDateOfMsg() + "');";
sqlcommand = mergeTblName( sqlcommand, CurrentAuditTable );
return sqlcommand;
// get users input char
/**public char getChar() {
int i = System.in.read();
while (i != -1) {
// here's your character
char c = (char) i;
i = System.in.read();
return (char) i;
// load the config parameters from config.txt
public void loadDbConfig() {
// make a file obj pointing to the config file config.txt
File configFile = new File( this.configFile );
//...checks on configFile are elided
StringBuffer contents = new StringBuffer();
//declared here only to make visible to finally clause
BufferedReader input = null;
try {
//use buffering
//this implementation reads one line at a time
input = new BufferedReader( new FileReader(configFile) );
String line = null; //not declared within while loop
int count = 0;
while (( line = input.readLine()) != null){
//first line in config file is dbPath
if(count == 0) this.setDbPath( line.trim() );
//second line in config file is ODBCDataSource
if(count == 1) this.setODBCDataSource( line.trim() );
count++;
//contents.append(line);
//contents.append(System.getProperty("line.separator"));
catch (FileNotFoundException ex) {
System.err.println("the file congif.txt cannot be found ...");
System.err.print("Enter the path to db file (e.g. c:\\temp): ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// read the db path from the command-line; need to use try/catch with the
// readLine() method
try {
this.setDbPath( br.readLine() );
catch (IOException ioe) {
System.out.println("IO error trying to read user input.");
System.exit(1);
System.err.print("Enter the name of the ODBC Data Source: ");
// read the ODBC Data Source name from the command-line; need to use try/catch with the
// readLine() method
try {
this.setODBCDataSource( br.readLine() );
catch (IOException ioe) {
System.out.println("IO error trying to read user input.");
System.exit(1);
ex.printStackTrace();
catch (IOException ex){
//ex.printStackTrace();
finally {
try {
if (input!= null) {
//flush and close both "input" and its underlying FileReader
input.close();
catch (IOException ex) {
//ex.printStackTrace();
//return contents.toString();
// get datasource security details i.e. username and password
public void getDSSecurity() {
// get username
System.out.print("Enter username for the ODBC DataSource: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// read the username from the command-line; need to use try/catch with the
// readLine() method
try {
this.setUsername( br.readLine() );
catch (IOException ioe) {
System.out.println("IO error trying to read username.");
System.exit(1);
// get password
System.out.print("Enter password: ");
// read the username from the command-line; need to use try/catch with the
// readLine() method
try {
this.setPassword( br.readLine() );
catch (IOException ioe) {
System.out.println("IO error trying to read password.");
System.exit(1);
private void dumpResults(String head)
//this is a general routine to print out
//column headers and the contents of each column
System.out.println(head);
try
//get the number of columns from the metadata
this.rsmd = this.tables.getMetaData();
numCols = this.rsmd.getColumnCount();
//print out the column names
for (i = 1; i<= numCols; i++)
System.out.print(rsmd.getColumnName(i)+" ");
System.out.println();
//print out the column contents
boolean more = this.tables.next();
while (more)
for (i = 1; i <= numCols; i++)
System.out.print(this.tables.getString(i)+" ");
System.out.println();
more = this.tables.next();
catch(Exception e)
{System.out.println(e.getMessage());}
/** Creates a new instance of dbManager */
public dbManager() {
this.dbInitialize();
}here is the result when I make a new dbManager obj from my server class which is a multithreaded one.
H:\java>java EchoServer
Enter username for the ODBC DataSource: admin
Enter password: purina123
Tables
TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS
Listening for clients on 12111...
here is the code of my server class called EchoServer:
import java.net.*;
import java.io.*;
public class EchoServer
ServerSocket m_ServerSocket;
dbManager haDB;
public EchoServer()
// db methods to setup a jdbc connection to the database
haDB = new dbManager();
// list tables
//haDB.listTables();
//haDB.getDBTables();
// create table
//haDB.CreateTable("TestTable2");
// update table
// server code
try
// Create the server socket.
m_ServerSocket = new ServerSocket(12111);
catch(IOException ioe)
System.out.println("Could not create server socket at 12111. Quitting.");
System.exit(-1);
System.out.println("Listening for clients on 12111...");
// Successfully created Server Socket. Now wait for connections.
int id = 0;
while(true)
try
// Accept incoming connections.
Socket clientSocket = m_ServerSocket.accept();
// accept() will block until a client connects to the server.
// If execution reaches this point, then it means that a client
// socket has been accepted.
// For each client, we will start a service thread to
// service the client requests. This is to demonstrate a
// multithreaded server, although not required for such a
// trivial application. Starting a thread also lets our
// EchoServer accept multiple connections simultaneously.
// Start a service thread
ClientServiceThread cliThread = new ClientServiceThread(clientSocket, id++, haDB);
cliThread.start();
catch(IOException ioe)
System.out.println("Exception encountered on accept. Ignoring. Stack Trace :");
ioe.printStackTrace();
public static void main (String[] args)
new EchoServer();
class ClientServiceThread extends Thread
Socket m_clientSocket;
int m_clientID = -1;
dbManager m_db;
boolean m_bRunThread = true;
ClientServiceThread(Socket s, int clientID, dbManager db)
m_clientSocket = s;
m_clientID = clientID;
m_db = db;
public void run()
// Obtain the input stream and the output stream for the socket
// A good practice is to encapsulate them with a BufferedReader
// and a PrintWriter as shown below.
BufferedReader in = null;
PrintWriter out = null;
Message msg = new Message();
// Print out details of this connection
System.out.println("Accepted Client : ID - " + m_clientID + " : Address - " +
m_clientSocket.getInetAddress().getHostName());
try
in = new BufferedReader(new InputStreamReader(m_clientSocket.getInputStream()));
out = new PrintWriter(new OutputStreamWriter(m_clientSocket.getOutputStream()));
// At this point, we can read for input and reply with appropriate output.
// Run in a loop until m_bRunThread is set to false
while(m_bRunThread)
// read incoming stream
String clientCommand = in.readLine();
if ( clientCommand.indexOf(",") != -1 ) {
msg.deserialize( clientCommand );
System.out.println("SQL command: " + m_db.mergeFldName(msg) );
m_db.dbUpdate( m_db.mergeFldName(msg) );
//System.out.println("Name :" + msg.getName() );
//System.out.println("Surname :" + msg.getSurname() );
//System.out.println("ComputerType :" + msg.getComputerType() );
//System.out.println("ComputerNAL :" + msg.getComputerNAL() );
//System.out.println("HaveMonitor :" + msg.getHaveMonitor() );
//System.out.println("Monitor NAL :" + msg.getMonitorNAL() );
//System.out.println("AuditDate :" + msg.getDateOfMsg() );
System.out.println("Client Says :" + clientCommand);
if(clientCommand.equalsIgnoreCase("quit"))
// Special command. Quit this thread
m_bRunThread = false;
System.out.print("Stopping client thread for client : " + m_clientID);
else
// Echo it back to the client.
out.println(clientCommand);
out.flush();
catch(Exception e)
e.printStackTrace();
finally
// Clean up
try
in.close();
out.close();
m_clientSocket.close();
System.out.println("...Stopped");
catch(IOException ioe)
ioe.printStackTrace();
}I find that taking any problem and reducing it to the simplest thing is the best way to approach it.
Why you had to post all that bloody code (especially since you didn't write it) is beyond me.
This will list all the tables in an Access database (or any other, for that matter):
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Element;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
public class TableLister
public static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String DATABASE = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\Edu\\Java\\Forum\\DataConnection.mdb";
public static final String USERNAME = "admin";
public static final String PASSWORD = "";
public static void main(String [] args)
try
String driver = ((args.length > 0) ? args[0] : DRIVER);
String url = ((args.length > 1) ? args[1] : DATABASE);
String username = ((args.length > 2) ? args[2] : USERNAME);
String password = ((args.length > 3) ? args[3] : PASSWORD);
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
DatabaseMetaData meta = conn.getMetaData();
// Bring back ALL tables and views, including SYSTEM tables.
ResultSet tables = meta.getTables(null, null, null, null);
ResultSetMetaData rsmd = tables.getMetaData();
int numColumns = rsmd.getColumnCount();
List columnNames = new ArrayList();
for (int j = 0; j < numColumns; ++j)
columnNames.add(rsmd.getColumnName(j+1));
Element root = new Element("tables");
int tableCount = 0;
while (tables.next())
Element table = new Element("table");
table.setAttribute("id", Integer.toString(++tableCount));
for (int j = 0; j < numColumns; ++j)
Element column = new Element((String)columnNames.get(j));
column.setText(tables.getString((String)columnNames.get(j)));
table.addContent(column);
root.addContent(table);
conn.close();
Document doc = new Document(root);
XMLOutputter outputter = new XMLOutputter(" ", true);
System.out.println(outputter.outputString(doc));
catch (ClassNotFoundException e)
System.err.println("Couldn't load JDBC driver class");
e.printStackTrace();
catch (SQLException e)
System.err.println("SQL state: " + e.getSQLState());
System.err.println("SQL error: " + e.getErrorCode());
e.printStackTrace();
catch (Exception e)
e.printStackTrace();
}Run it and see if it works for you. If it does, put the essence of the code into your stuff.
% -
How to connect to ms access database in jdbc
i want to connect to my ms access database located in my c:\tapi\dbexperts.mdb. please help me construct the connection string. thanks in advance for your help.
String database = "c:\\tapi\\dbexperts.mdb"; /* change it*/
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + database + ";DriverID=22;READONLY=false";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url); -
Exception connecting to MS Access Database.
I'm having problems using the jdbc-odbc bridge with an MS Access database and a file DSN. If I use a system DSN, it works fine but it does not seem to find the file DSN for some reason (And I HAVE to use a file DSN in this instance, for reasons I won't bore you with) - this is the error-message:
"java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
This is my example code:
import java.sql.*;
public class SamplePgm {
private static Connection con;
private static Statement stmt;
private static ResultSet result;
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Testing", "", "");
stmt = conn.createStatement();
result = stmt.executeQuery("select TOP 3 emp_no from employee");
while (result.next()) {
System.out.println(result.getString("emp_no"));
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
result.close();
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
The file DSN was set up using the Win2K ODBC administrator.
Is there any other way to tell ODBC that it's using a file DSN ?
I'd be very grateful for any/all assistance.
Thanks.My guess would be that a file DSN is stored in a file, a system DSN is stored under the HKeyLocalMachine registry key and a user DSN is stored under the HKeyCurrentUser registry key, but it's only a guess.
-
How to connect with Microsoft Access Database with JAVA
I want to know the command and query to connect between MSAccess and JDBC.
Is it beter way to make connection with MSAccess comparing with other Databases such as SQL and Oracle.
Which Database will be the best with Java?
I also want to know to be platform indepadent which database is suitable?On Windows, you can use MS Access database by:
Set up a System Data Source using the ODBC control panel applet.
Use the jdbc:odbc bridge JDBC driver, and specify a jdbc url that points to the data source name you just specified.
It's been too long since I've done this, so I don't remember the syntax of the jdbc url, but I'm sure that if you do a search for the jdbc:odbc bridge that you will find what you are looking for.
As far as the question about which database is best, you will need to determine that based on your project requirements.
If you want a quick and dirty, open source, cross-platform database, take a look at HyperSonic SQL.
- K -
CONNECT BI7 TO ACCESS DATABASE
<Moderator Message: Don't use upper case letters; Don't request documentation or links; Search the forums; follow the rules>
Hello,
Is it possible to connect Microsoft Access database to BW.
Should i use DB connect or UD connect.
If someone could provide simple documentation
thanks for you help,
Edited by: Siegfried Szameitat on Dec 9, 2008 12:02 PMHi there!
I think data binding is being added to netbeans 6 next year, otherwise you will have to use JDBC to access the database and call setText for the field with the data you get out of the db (manual coding). Google for the jdbc odbc bridge for accessing Access DB.
For data binding you can use Swing X http://www.swinglabs.org/projects.jsp, as long as you don't mind writing code by hand.
In the mean time, if you really want to do the binding using drag and drop you can use the Visual Web pack for netbeans 5.5 and create a web based app with data binding. If you wait a week or two the final version (preview can be downloaded at the moment) of the web pack should be released.
Sorry about the tone of the other guy's comment, it seems that Java programmers are traditionally hostile towards VB guys and how they view the world ;) -
Cannot connect to an Access database from DreamWeaver
Hello.
I'm creating my first web page with a DB connection.
I have a minimal DB with a simple table.
This is a DB as Access create it by default, with no password
and no
security constraints.
In DreamWeaver, I have created a default DB connection string
for Access
2000.
I have removed, from this connection string, the UserID and
the Password as
there is no password for my DB.
I have put the right path for this DB.
But it doesn't work!
I receive the message: (sorry for my bad english) cannot open
the DB, it is
already open by another user (it is not the case: the DB is
closed) or you
must have autorisation to visualised the data.
Do you have an idea ?
Alain."chucknado" <[email protected]> a écrit
dans le message de
news:fbnon3$47m$[email protected]..
> You might have a file or folder permissions problem.
Please see the
following:
>
>
>
http://livedocs.adobe.com/en_US/Dreamweaver/9.0/WSc78c5058ca073340dcda9110b1f693
> f21-79f0.html
>
> Charles Nadeau
> Dreamweaver
> Adobe Systems
>
I'm not an expert in file permissions so I have simply moved
my DB on the
HDD of my PC, before it was on another server.
So, now, I think I have no file permission problem anymore.
I can connect the DB from DreamWeaver but I cannot see the
tables !
If I open the Tables node of the db tree in the Database
window of
DreamWeaver, I receive the message:
"Error calling GetTables".
Do you have an idea or an advice ?
Thanks in advance,
Alain. -
Connection to ODBC access database failure
I have made several sites using ACCESS databases via ODBC DSN
name. But suddenly it does not work any more. I can not use the
Database wizards in DM 8.02. When I have made a connection, tested
it OK and I try to se the tables/views. I only got the word "none".
If I in the advanced recordset wizard write the SQL command, the
data is showen correctly!!???
There is something wrong with DM's abillitry to connect to
the ODBC DNS name...Everything is updateted to the latest version.
Is there anybody who have any clue to what could be wrong. It
is the same story on an old 2000 Server, a new 2003 small busines
server and from DM installed on two different clientmaschines and
on the two servers.Hi!
You could try this It worked for me on all my connections.
I found a extension called SP2DBFix1.0.2.mxp
Down load here,
http://download.macromedia.com/pub/dreamweaver/extensions/SP2DBFix1.0.2.mxp
to fix a XP pro service pack2 connections.
To fix: I went to Sites/Advanced/Remove connection Scripts,
ran that removed
my
connection scripts. I then shut down Dreamweaver 8 installed
the extension
then opened dreamweaver 8 made a new connection and it works
now Great! Im
happy.
You have to run this same routine on every site you have
setup with
connection scripts
Good Luck.
Dave
"JOhnny Odgaard" <[email protected]> wrote
in message
news:ersvva$2hd$[email protected]..
> I have made several sites using ACCESS databases via
ODBC DSN name. But
> suddenly it does not work any more. I can not use the
Database wizards in
DM
> 8.02. When I have made a connection, tested it OK and I
try to se the
> tables/views. I only got the word "none". If I in the
advanced recordset
wizard
> write the SQL command, the data is showen correctly!!???
>
> There is something wrong with DM's abillitry to connect
to the ODBC DNS
> name...Everything is updateted to the latest version.
>
> Is there anybody who have any clue to what could be
wrong. It is the same
> story on an old 2000 Server, a new 2003 small busines
server and from DM
> installed on two different clientmaschines and on the
two servers.
> -
Trying to connect to an Access database
Post Author: robert693
CA Forum: Deployment
Hello,
I am trying to use Crystal to create reports out of an Access database. When I try to connect to the database thru the database expert, I go to Create Connection and choose Databse Files. I choose a database that is in My Documents. I get an error that says "Failed to load database information," and then "Unknown Query Engine Error." I was wondering what I have to do to connect to the Access database.
Any help would be greatly appreciated!
RobertPost Author: [email protected]
CA Forum: Deployment
I connect to Access by first creating an ODBC connection to it and then have crystal use the ODBC. -
Connect to remote Access database
Hi there,
Can any one tell me how to connect to the remote MS Access? The scnario is:
Suppose there is a web server with IP 215.167.16.89. The JDBC driver (assumed to be JDataConnect) is installed on this machine. How to use this web server to connect to the Access database called db1.mdb with DSN 'db1' held in the maching with IP 165.247.17.43?
The Jave connection codes I am using are:
String url=new String ("jdbc:JDataConnect://165.247.17.43/db1:username:password");
try{
drvDriver=(Driver)Class.forName("JData2_0.sql.$Driver").newInstance();
conConnection = drvDriver.connect(url, new Properties());
showMessage("Connected to Company2 Database");
Why can I not connect to the db1 database?
If I use these codes to connect to the database in the same machine as the web server without specifying the IP address, it worked.
String url=new String ("jdbc:JDataConnect:db1:username:password");
Thanks in advance.Thanks for the help.
So you need to give a full path of it as if you are accesing
through windows explorer.I am not sure how to give a full path. Can you give me the detail please?
What happens when you have two or more .mdb with the
same name in different directories in that ip address.
Since its a file... you need to access it as a file.I think we can specify the different DSN for the two or more .mdb databases.
Thanks. -
Is it Possible to upload the output from Oracle reports To Access database
Hi All,
Wish you All a Very Happy New Year.
I have a query.Is it possible to
upload the output from the Oracle reports
to the Access database???
Any suggestions would be appreciated.
TIA
sgHi sg,
Research the DDE option.
Dynamic Data Exchange (DDE) is a mechanism by which applications can communicate and exchange data in Windows.
I have imported data into the excel spreadsheet using DDE built in functions. I am sure it can work with MS Acess as well. If not, then you need to create a 2 step process .. reports -> excel -> access.
Maybe you are looking for
-
Question of displaying Task Flow Region in Master-Details pattern
We have a master-details page. There is a region on the details pane along with other widgets and the content of that details pane including the region depends on the row selection on the master table list. The first time page loads with no row selec
-
Not showing video while loading
My quicktime is not showing the video on quicktime movies, primarily on the apple website and i'm perplexed as to why. It will play the audio while it is loading and once it has loading i can refresh and it will play the audio and video... any ideas
-
Urgent : FLTP to time conversion
I have used the function module as C14W_NUMBER_CHAR_CONVERSION for time conversion. But it produces the output as follows. E_STRING 86,400.000000000 E_FLOAT 8.6400000000000000E+04 E_DEC
-
ERROR: "You are not assigned to a role" in BEx
Hi, I have a user <i>BEXUSER</i>. In <b>PFCG</b>, I have assigned this user to a role <i>ZR_USER_ROLE</i>. However, when I tried to open a query in BEx Anlyzer through <b>Open > Workbooks > Roles</b> toolbar, I could not find any workbooks assigned t
-
My library randomly changed the order in which my songs were (alphabetically). It always listed artists with with symbols (such as +44), then numbers 0-9, and then A-Z. I opened iTunes this morning and it had changed the order to A-Z, THEN symbols an