Write java to connect to MS SQL server
Hello all, I'm working on a project for my class to compare the schema of two MS SQL database which write in Java. I'm doing a module called: Networking, which connect to the database and take out the data from it. So I have two questions to ask: (if someone can give me a sample code, i will be thankful)
1. How do I connect to MS SQL after the user pass in the parameters as usename, password and ip (or servername)?
2. After login how do I take the data out of the database?
3. How do I apply a query to MS SQL by java?
I'm appreciated if anyone can answers my questions.
Thank you
Mr. Nice Guy, this is hardly an advanced topic. Look at the Tutorials link to your left first from now on.
Here's sample code that will get you started:
package be;
import java.sql.*;
import java.util.*;
public class DataConnection
public static final String DEFAULT_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String DEFAULT_URL = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\Software\\Java\\Forum\\DataConnection.mdb";
public static final String DEFAULT_USERNAME = "admin";
public static final String DEFAULT_PASSWORD = "";
/** Database connection */
private Connection connection;
* Driver for the DataConnection
* @param command line arguments
* <ol start='0'>
* <li>SQL query string</li>
* <li>JDBC driver class</li>
* <li>database URL</li>
* <li>username</li>
* <li>password</li>
* </ol>
public static void main(String [] args)
DataConnection db = null;
try
if (args.length > 0)
String sql = args[0];
String driver = ((args.length > 1) ? args[1] : DEFAULT_DRIVER);
String url = ((args.length > 2) ? args[2] : DEFAULT_URL);
String username = ((args.length > 3) ? args[3] : DEFAULT_USERNAME);
String password = ((args.length > 4) ? args[4] : DEFAULT_PASSWORD);
db = new DataConnection(driver, url, username, password);
List result = db.query(sql);
System.out.println(result);
else
System.out.println("Usage: db.DataConnection <sql> <driver> <url> <username> <password>");
catch (SQLException e)
System.err.println("SQL error: " + e.getErrorCode());
System.err.println("SQL state: " + e.getSQLState());
e.printStackTrace(System.err);
catch (Exception e)
e.printStackTrace(System.err);
finally
if (db != null)
db.close();
db = null;
* Create a DataConnection
* @throws SQLException if the database connection fails
* @throws ClassNotFoundException if the driver class can't be loaded
public DataConnection() throws SQLException,ClassNotFoundException
this(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
* Create a DataConnection
* @throws SQLException if the database connection fails
* @throws ClassNotFoundException if the driver class can't be loaded
public DataConnection(final String driver,
final String url,
final String username,
final String password)
throws SQLException,ClassNotFoundException
Class.forName(driver);
this.connection = DriverManager.getConnection(url, username, password);
* Clean up the connection
public void close()
try
this.connection.close();
catch (Exception e)
; // do nothing; you've done your best
* Execute an SQL query
* @param SQL query to execute
* @returns list of row values
* @throws SQLException if the query fails
public List query(final String sql) throws SQLException
Statement statement = this.connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
ResultSetMetaData meta = rs.getMetaData();
int numColumns = meta.getColumnCount();
List rows = new ArrayList();
while (rs.next())
Map thisRow = new LinkedHashMap();
for (int i = 1; i <= numColumns; ++i)
String columnName = meta.getColumnName(i);
Object value = rs.getObject(columnName);
thisRow.put(columnName, value);
rows.add(thisRow);
rs.close();
statement.close();
return rows;
}MOD
Similar Messages
-
Java Concurrent Program - connecting to MS SQL Server
Hi,
I hope this is correct forum to post this question.
I am writing a JCP which will connect to a MS SQL Server DB, pull data from a table and populate this data into a custome table in EBS (R12.1.1) database. But I am facing some issues.
When I run run this concurrent program from EBS, I get following exception message:
Wed Aug 08 01:18:04 GMT 2012: In openConection()
Wed Aug 08 01:18:04 GMT 2012: Before Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver
Wed Aug 08 01:18:04 GMT 2012: openConection() ClassNotFoundException: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
Wed Aug 08 01:18:04 GMT 2012: Before Calling processPrintMachineRecords()
Wed Aug 08 01:18:04 GMT 2012: Exception:: java.lang.NullPointerException
Wed Aug 08 01:18:04 GMT 2012: In closeSQLServerConnection().......closing JDBC Connection
Wed Aug 08 01:18:04 GMT 2012: Connection object was null, hence skipping close
Wed Aug 08 01:18:04 GMT 2012: After Calling processPrintMachineRecords()
The I read somewhere on internet that I should set CLASSPATH in options field of concurrent program definition. So I provided classpath as follows:
-cp /rs01/u02/applmgr/utyeb02/apps/apps_st/appl/au/12.0.0/appsborg.zip:/rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/classes/apps.zip:/rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/classes/sqljdbc_4.0/enu/sqljdbc.jar
In this classpath sqljdbc.jar contains the classes for connecting to MS SQL Server DB. However after giving classpath like this I started getting different error:
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/apps/fnd/cp/request/Run
Caused by: java.lang.ClassNotFoundException: oracle.apps.fnd.cp.request.Run
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
It appears from the error message that after giving this CLASSPATH, program was not able to find the "Run" method itself. In otherwords, CLASSPATH screwed it further.
Can anybody please point out what am I doing wrong here?
Regards
Java Code:
package oracle.apps.custom.printmachine;
import java.sql.*;
import oracle.apps.fnd.cp.request.* ;
import java.io.*;
import oracle.apps.fnd.util.*;
public class PrintMachineInterface implements JavaConcurrentProgram {
public static final String M_SUCCESS = "SUCCESS";
public static final String M_ERROR = "ERROR";
public static final String M_WARNING = "WARNING";
int mRequestStatus = -1;
int max_number_of_records = 99999999;
private String mSqlServerHost = "mysqlserver.domain.com";
// Application Short Name
private String applName;
CpContext mCtx;
LogFile logFile;
OutFile outFile;
Connection mConn = null;
ReqCompletion lRC;
public PrintMachineInterface(){
// if no parameter value is specified for APPLNAME then use FND
//as default value
applName = "FND";
private void logMessage(String str) {
java.util.Date now = new java.util.Date();
logFile.writeln(now.toString() + ": " + str, LogFile.STATEMENT);
static String mInsertRecord = " Declare " + " BEGIN "
+ " INSERT INTO XXGFN_GBL_CE_PM_STAGE(ID, KEY, FILENAME, PRINTED_AT, CREATED_AT, DOCTYPE, LANGUAGE, OU, TRX_ID, DOC_ID, REQ_ID, TEMPLATE, PAGES, DOC_TEXT, TIMES_RECEIVED)"
+ " VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, substr(:14,2000), :15);"
+ " COMMIT;"
+ " END;";
static Connection con = null;
public void openConection() {
logMessage( "In openConection()");
try {
logMessage( "Before Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
logMessage( "After Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver");
logMessage( "Attempting to connect to " + mSqlServerHost);
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + mSqlServerHost + ":1433;User=sql_user;Password=sql_pwd");
logMessage( "After con assigned from getConnection(jdbc:microsoft:sqlserver://" + mSqlServerHost + ":1433;User=pm_dba_access;Password=*****");
} catch (java.lang.ClassNotFoundException e) {
logMessage("openConection() ClassNotFoundException: " + e);
} catch (SQLException ex) {
logMessage("openConection() SQLException: " + ex);
public void closeSQLServerConnection() {
try {
logMessage( "In closeSQLServerConnection().......closing JDBC Connection");
if (con != null)
logMessage( "Con is not null");
con.close();
logMessage( "Con Closed Successfully");
else
logMessage( "Connection object was null, hence skipping close");
} catch (SQLException ex) {
logMessage("SQLException: " + ex);
} catch (Exception ex) {
logMessage("Exception in closeSQLServerConnection() : " + ex);
private void populate_staging_table(
String p_id,
String p_key,
String p_filename,
String p_printed_at,
String p_created_at,
String p_doctype,
String p_language,
String p_ou,
String p_trx_id,
String p_doc_id,
String p_req_id,
String p_template,
String p_pages,
String p_doc_text,
String p_times_received
PreparedStatement lStmt = null;
logMessage("Populating data from PrintMachine history table");
try {
lStmt = mConn.prepareCall(mInsertRecord);
lStmt.setString(1, p_id);
lStmt.setString(2, p_key);
lStmt.setString(3, p_filename);
lStmt.setString(4, p_printed_at);
lStmt.setString(5, p_created_at);
lStmt.setString(6, p_doctype);
lStmt.setString(7, p_language);
lStmt.setString(8, p_ou);
lStmt.setString(9, p_trx_id);
lStmt.setString(10, p_doc_id);
lStmt.setString(11, p_req_id);
lStmt.setString(12, p_template);
lStmt.setString(13, p_pages);
lStmt.setString(14, p_doc_text);
lStmt.setString(15, p_times_received);
lStmt.execute();
lStmt.close();
} catch (SQLException s) {
logMessage("Exception thrown w/ error message: "
+ s.getMessage());
s.printStackTrace();
finally {
try {
if (lStmt != null)
lStmt.close();
} catch (SQLException e) {
logMessage("SQLException: " + e);
private void processPrintMachineRecords() {
int number_of_recs = 0;
try {
PreparedStatement stmt = con.prepareStatement("SELECT TOP 1000 ID, Key, Filename, PrintedAt, CreatedAt, Doctype, Language,OU, TransactionID, DocumentID, RequestID, Template, Pages, Documenttext, TimesReceived FROM PM_DATA.dbo.History" );
ResultSet rst = stmt.executeQuery();
while (rst.next()) {
number_of_recs++;
if (number_of_recs == max_number_of_records) break;
populate_staging_table(
rst.getString(1), rst.getString(2)
,rst.getString(3), rst.getString(4)
,rst.getString(5), rst.getString(6)
,rst.getString(7), rst.getString(8)
,rst.getString(9), rst.getString(10)
,rst.getString(11), rst.getString(12)
,rst.getString(13), rst.getString(14)
,rst.getString(15)
stmt.close();
rst.close();
mConn.commit();
} catch (SQLException ex) {
logMessage("SQLException: " + ex);
catch (Exception ex) {
logMessage("Exception:: " + ex);
closeSQLServerConnection();
public void runProgram(CpContext pCpContext) {
applName = "XXGFN";
String l_file_path = null;
mCtx = pCpContext;
//get handle on request completion object for reporting status
lRC = pCpContext.getReqCompletion();
// assign logfile
logFile = pCpContext.getLogFile();
// assign outfile
outFile = pCpContext.getOutFile();
// get the JDBC connection object
mConn = pCpContext.getJDBCConnection();
l_file_path = ((new File(outFile.getFileName())).getParent() == null ? ""
: (new File(outFile.getFileName())).getParent());
// get parameter list object from CpContext
ParameterList lPara = pCpContext.getParameterList();
while (lPara.hasMoreElements())
NameValueType aNVT = lPara.nextParameter();
if ( aNVT.getName().equals("APPLNAME") )
applName = aNVT.getValue();
/** openConection() Opens the connection to SQL Server Database*/
openConection() ;
logMessage("Before Calling processPrintMachineRecords()");
processPrintMachineRecords();
logMessage("After Calling processPrintMachineRecords()");
try{
setCompletion(ReqCompletion.NORMAL, "Request Completed Normal");
} catch (Exception e) {
setCompletion(ReqCompletion.ERROR, e.toString());
} finally {
pCpContext.releaseJDBCConnection();
* Sets the request completion status based on proper precedence. ERROR >
* WARNING > NORMAL
* @param pStatus
* Status of the request.
* @param pCompletionText
* Request's completion text.
public void setCompletion(int pStatus, String pCompletionText) {
if ((pStatus == ReqCompletion.ERROR)
|| ((pStatus == ReqCompletion.WARNING) && (mRequestStatus != ReqCompletion.ERROR))
|| ((pStatus == ReqCompletion.NORMAL)
&& (mRequestStatus != ReqCompletion.WARNING) && (mRequestStatus != ReqCompletion.ERROR))) {
mRequestStatus = pStatus;
lRC.setCompletion(pStatus, pCompletionText);
}ok
i used Template.java as input
useful MOS:
How To Create a Java Concurrent Program? [ID 827563.1]
Java Concurrent Program FAQ [ID 827575.1]
i used
//goto ms sql server 2008r2
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = java.sql.DriverManager.getConnection(
"jdbc:sqlserver://1.2.3.4:1433;databaseName=test;selectMethod=cursor",
"test", "test");
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}1.2.3.4 - ip of instance with sqlserver2008r2 :)
in your code
>
try {
logMessage( "Before Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
logMessage( "After Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver");
logMessage( "Attempting to connect to " + mSqlServerHost);
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + mSqlServerHost + ":1433;User=sql_user;Password=sql_pwd");
logMessage( "After con assigned from getConnection(jdbc:microsoft:sqlserver://" + mSqlServerHost + ":1433;User=pm_dba_access;Password=*****");
} catch (java.lang.ClassNotFoundException e) {
logMessage("openConection() ClassNotFoundException: " + e);
} catch (SQLException ex) {
logMessage("openConection() SQLException: " + ex);
>
try my case for Driver and Connection
put result .class file to needed directory
put sqljdbc4.jar to /rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/lib
and for concurrent program option
-classpath /rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/classes:/rs01/u02/applmgr/utyeb02/apps/apps_st/appl/au/12.0.0/appsborg.zip:/rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/lib/sqljdbc4.jaralso useful mos:
Classpath Setting of Third Party Jar Files in R12 Java Concurrent Program (JCP) [ID 1292694.1] -
Connect to MS Sql Server from Java Source
Hi,
Is there any way I could connect to ms sql server from Java source? I know I can call java source from function thats easy but what I really want is capability to connect to non-oracle(MS SQL server) from my java source and then call it from function.
I don't know if JDBC driver for SQL server is even installed/available. Is there a way I could find it out form my IDE? I know sqlJ does compile but I have never used sqlj. help!!!
SinhaYou'll probably have better luck in a Java forum or a Microsoft forum.
-
Connection pooling with SQL Server 2008 and Tomcat 6.0
Hello Everybody,
I'm creating a web application using struts 2.0 , tomcat 6.0 and sql server 2008.
Everything works fine but i'm unable to create connection pooling with sql server 2008.Please help me to solve this issue.
Code for this is as foolows:
in my META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/spas" docBase="spas"
debug="5" reloadable="true" crossContext="true">
<Resource
name="jdbc/spas_new"
auth="Container"
type="javax.sql.DataSource"
maxActive="20"
maxIdle="10"
maxWait="-1"
user="spas_user"
password="spas123"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://HGL-0053\dbo:1433;databaseName=spas_new;responseBuffering=adaptive;"/>
</Context>
in my web.xml
<resource-ref>
<description>SQL Server Datasource</description>
<res-ref-name>jdbc/spas_new</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and in my ConnectionThread.java file i've used:
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Sorry! No Context Exception");
DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/spas_new");
System.out.println("ds:"+ds);
conn=ds.getConnection();
Following is the exception:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Login failed for user ''.)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at login.V_SPAS_ConnectionThread.getConnection(V_SPAS_ConnectionThread.java:87)
at org.apache.jsp.login.v_005fspas_005flogin_005fpage_jsp._jspService(v_005fspas_005flogin_005fpage_jsp.java:95)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1023)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:572)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:54)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at login.V_SPAS_SecurityCheckFilter.doFilter(V_SPAS_SecurityCheckFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ''.Hi Karthikeyan,
This is not the issue at all. I can open the management studio by the same login id and password and also i can make the database jdbc connection from plain java file.
It does not give me any problem by them.
I'm unable to find the actual problem. May be i'm missing something in connection pooling.
Please help.
Regards
Mina -
Connect to MS SQL Server 2000 data warehouse
Hi,
I use a MS SQL Server 2000 database for my web application where I use JSP. I suppose to create data warehouse using MS SQL Server's Data Transformation Service. But I don't know it's possible to connect to a MS SQL Server's data warehouse using JSP. So I want to know is it possible to connect to data warehouse using JSP and if it is how to do it? Thank you.You can certainly connect to M$ SQL Server using the JDBC driver:
http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&displaylang=en
Connecting to a data warehouse is no different from any relational database. (My understanding is that a data warehouse usually means a star schema implemented in a relational database.) This will connect you.
If you're not familiar with JDBC, you might need the tutorial:
http://java.sun.com/docs/books/tutorial/jdbc/ -
Connect to MS SQL server from OWB on Linux platform
Hi,
I want to connect to MS SQL server through OWB, on Linux platform.
I suppose I would use JDBC driver, and Heterogeneous services. Is that possible?
I did not see anything on JDBC driver for MS SQL server for Linux platform from Oracle.
Also, I was wondering is Oracle Gateway 10g for Linux a way to connect to MSSQL server?
Any leads would be appreciated.
Thanks
AniHi,
This quite an actual topic for myself, so I decided to take some time to collect some information.
Start at:
* Oracle Generic Connectivity and Oracle Transparent Gateway - http://www.oracle.com/technology/products/gateways/gateways_fov.html
You can use the free Heterogenous Services component named Generic Connectivity for connecting to SqlServer over ODBC. You will need to find (or purchase?) a third-party ODBC driver for SqlServer for Linux, e.g. from www.datadirect.com. Setting this up will allow you to define a databaselink to the SqlServer. Open Gateways implements a limited set of the oracle SQL, so you will have to find out what is possible and what not.
See also:
* How To Setup HSODBC on Linux - https://metalink.oracle.com/metalink/plsql/showdoc?db=NOT&id=264567.1
* Generic Connectivity Available on Linux x86 with 10g - https://metalink.oracle.com/metalink/plsql/showdoc?db=NOT&id=261726.1
You can also use the Transparent Gateway for SqlServer (HS), which is about EURO 12000 per computer(!). This gives you a full implementation of Oracle SQL and you can access the SqlServer like it was Oracle.
You can also install Microsofts JDBC drivers into Oracle's JVM, and connect through JDBC to SqlServer. This is however not supported by Oracle, but it will work. See:
* What is required for a Java Stored Procedure to connect to a SQL Server Database? - https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=276167.1
See also:
* Options for Connecting to Foreign Data Stores and Non-Oracle Databases - https://metalink.oracle.com/metalink/plsql/showdoc?db=NOT&id=233876.1
* JDBC Developer's Guide - http://download-west.oracle.com/docs/cd/B14117_01/java.101/b10979/overvw.htm
Good luck, Erik Ykema -
Connect to Microsoft SQL server 2012
HI,
Currently My OSB connects to MS SQL server to get some data and then construct the request to submit to another web service. But recently the SQL server that I connect to has upgraded(previously was MS SQL 2005) to MS SQL to 2012. There are certain properties that needs to be changed in the connection property(for example : ApplicationIntent=ReadOnly) and I am not sure where to change this connection property. I am using sqljdbc4.jar for connectivity. Please advice. This is a bit urgent and appreciate if someone can help me out ASAP.
After the upgrade I am not able to connect to the SQL server DB as well. This is the error
Invoke JCA outbound service failed with application error, exception: com.bea.wli.sb.transports.jca.JCATransportException: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/SGH/LabResults/SCMLabService [ SCMLabService_ptt::SCMLabService(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'SCMLabService' failed due to: Could not create/access the TopLink Session.
This session is used to connect to the datastore.
Caused by Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/myAPPConn].
Internal Exception: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.myAPPConn'. Resolved 'jdbc'; remaining name 'myAPPConn'.
; nested exception is:
BINDING.JCA-11622
Could not create/access the TopLink Session.
This session is used to connect to the datastore.
Caused by Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/myAPPConn].
Internal Exception: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.myAPPConn'. Resolved 'jdbc'; remaining name 'myAPPConn'.
You may need to configure the connection settings in the deployment descriptor (i.e. DbAdapter.rar#META-INF/weblogic-ra.xml) and restart the server. This exception is considered not retriable, likely due to a modelling mistake.
com.bea.wli.sb.transports.jca.JCATransportException: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/SGH/LabResults/SCMLabService [ SCMLabService_ptt::SCMLabService(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'SCMLabService' failed due to: Could not create/access the TopLink Session.
This session is used to connect to the datastore.
Caused by Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/myAPPConn].
Internal Exception: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.myAPPConn'. Resolved 'jdbc'; remaining name 'myAPPConn'.
; nested exception is:
BINDING.JCA-11622
Could not create/access the TopLink Session.
This session is used to connect to the datastore.
Caused by Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/myAPPConn].
Internal Exception: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.myAPPConn'. Resolved 'jdbc'; remaining name 'myAPPConn'.
You may need to configure the connection settings in the deployment descriptor (i.e. DbAdapter.rar#META-INF/weblogic-ra.xml) and restart the server. This exception is considered not retriable, likely due to a modelling mistake.
at com.bea.wli.sb.transports.jca.binding.JCATransportOutboundOperationBindingServiceImpl.invoke(JCATransportOutboundOperationBindingServiceImpl.java:155)
at com.bea.wli.sb.transports.jca.JCATransportEndpoint.sendRequestResponse(JCATransportEndpoint.java:209)
at com.bea.wli.sb.transports.jca.JCATransportEndpoint.send(JCATransportEndpoint.java:170)
at com.bea.wli.sb.transports.jca.JCATransportProvider.sendMessageAsync(JCATransportProvider.java:571)
at sun.reflect.GeneratedMethodAccessor1269.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.bea.wli.sb.transports.Util$1.invoke(Util.java:83)
at $Proxy143.sendMessageAsync(Unknown Source)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageAsync(LoadBalanceFailoverListener.java:148)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageToServiceAsync(LoadBalanceFailoverListener.java:603)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageToService(LoadBalanceFailoverListener.java:538)
at com.bea.wli.sb.transports.TransportManagerImpl.sendMessageToService(TransportManagerImpl.java:558)
at com.bea.wli.sb.transports.TransportManagerImpl.sendMessageAsync(TransportManagerImpl.java:426)
at com.bea.wli.sb.test.service.ServiceMessageSender.send0(ServiceMessageSender.java:377)
at com.bea.wli.sb.test.service.ServiceMessageSender.access$000(ServiceMessageSender.java:76)
at com.bea.wli.sb.test.service.ServiceMessageSender$1.run(ServiceMessageSender.java:134)
at com.bea.wli.sb.test.service.ServiceMessageSender$1.run(ServiceMessageSender.java:132)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at com.bea.wli.sb.security.WLSSecurityContextService.runAs(WLSSecurityContextService.java:55)
at com.bea.wli.sb.test.service.ServiceMessageSender.send(ServiceMessageSender.java:137)
at com.bea.wli.sb.test.service.ServiceProcessor.invoke(ServiceProcessor.java:454)
at com.bea.wli.sb.test.TestServiceImpl.invoke(TestServiceImpl.java:172)
at com.bea.wli.sb.test.client.ejb.TestServiceEJBBean.invoke(TestServiceEJBBean.java:167)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl.invoke(TestService_sqr59p_EOImpl.java:353)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:174)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:345)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl_1033_WLStub.invoke(Unknown Source)
at com.bea.alsb.console.test.TestServiceClient.invoke(TestServiceClient.java:174)
at com.bea.alsb.console.test.actions.DefaultRequestAction.invoke(DefaultRequestAction.java:117)
at com.bea.alsb.console.test.actions.DefaultRequestAction.execute(DefaultRequestAction.java:70)
at com.bea.alsb.console.test.actions.ServiceRequestAction.execute(ServiceRequestAction.java:143)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.access$201(PageFlowRequestProcessor.java:97)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor$ActionRunner.execute(PageFlowRequestProcessor.java:2044)
at org.apache.beehive.netui.pageflow.interceptor.action.internal.ActionInterceptors.wrapAction(ActionInterceptors.java:91)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processActionPerform(PageFlowRequestProcessor.java:2116)
at com.bea.alsb.console.common.base.SBConsoleRequestProcessor.processActionPerform(SBConsoleRequestProcessor.java:91)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processInternal(PageFlowRequestProcessor.java:556)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.process(PageFlowRequestProcessor.java:853)
at com.bea.alsb.console.common.base.SBConsoleRequestProcessor.process(SBConsoleRequestProcessor.java:191)
at org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.process(AutoRegisterActionServlet.java:631)
at org.apache.beehive.netui.pageflow.PageFlowActionServlet.process(PageFlowActionServlet.java:158)
at com.bea.console.internal.ConsoleActionServlet.process(ConsoleActionServlet.java:256)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at com.bea.console.internal.ConsoleActionServlet.doGet(ConsoleActionServlet.java:133)
at com.bea.alsb.console.common.base.SBConsoleActionServlet.doGet(SBConsoleActionServlet.java:49)
at org.apache.beehive.netui.pageflow.PageFlowUtils.strutsLookup(PageFlowUtils.java:1199)
at org.apache.beehive.netui.pageflow.PageFlowUtils.strutsLookup(PageFlowUtils.java:1129)
at com.bea.portlet.adapter.scopedcontent.ScopedContentCommonSupport.executeAction(ScopedContentCommonSupport.java:687)
at com.bea.portlet.adapter.scopedcontent.ScopedContentCommonSupport.processActionInternal(ScopedContentCommonSupport.java:142)
at com.bea.portlet.adapter.scopedcontent.StrutsStubImpl.processAction(StrutsStubImpl.java:76)
at com.bea.portlet.adapter.NetuiActionHandler.raiseScopedAction(NetuiActionHandler.java:111)
at com.bea.netuix.servlets.controls.content.NetuiContent.raiseScopedAction(NetuiContent.java:181)
at com.bea.netuix.servlets.controls.content.NetuiContent.raiseScopedAction(NetuiContent.java:167)
at com.bea.netuix.servlets.controls.content.NetuiContent.handlePostbackData(NetuiContent.java:225)
at com.bea.netuix.nf.ControlLifecycle$2.visit(ControlLifecycle.java:180)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:324)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:130)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:395)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:361)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:352)
at com.bea.netuix.nf.Lifecycle.runInbound(Lifecycle.java:184)
at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:159)
at com.bea.netuix.servlets.manager.UIServlet.runLifecycle(UIServlet.java:388)
at com.bea.netuix.servlets.manager.UIServlet.doPost(UIServlet.java:258)
at com.bea.netuix.servlets.manager.UIServlet.service(UIServlet.java:199)
at com.bea.netuix.servlets.manager.SingleFileServlet.service(SingleFileServlet.java:251)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.AsyncInitServlet.service(AsyncInitServlet.java:130)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:330)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/SGH/LabResults/SCMLabService [ SCMLabService_ptt::SCMLabService(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'SCMLabService' failed due to: Could not create/access the TopLink Session.
This session is used to connect to the datastore.
Caused by Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/myAPPConn].
Internal Exception: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.myAPPConn'. Resolved 'jdbc'; remaining name 'myAPPConn'.
; nested exception is:
BINDING.JCA-11622
Could not create/access the TopLink Session.
This session is used to connect to the datastore.
Caused by Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/myAPPConn].
Internal Exception: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.myAPPConn'. Resolved 'jdbc'; remaining name 'myAPPConn'.
You may need to configure the connection settings in the deployment descriptor (i.e. DbAdapter.rar#META-INF/weblogic-ra.xml) and restart the server. This exception is considered not retriable, likely due to a modelling mistake.
Thanks in advance
SridharHi All,
I really appreciate your valuable inputs. My hair about to fall because of this problem
L
Tom, thanks, I have gone through that article weeks ago, but no luck
J
The Summary:
I have made a work around to resolve my problem. I have created a new virtual server on the second physical DELL server (with SQL Express 2012).
The problem seems to be a network issue on the hyper-V virtual switch!!
More details:
As described previously, VS connects to SQL service within the same Hyper-V only, although all configuration are right. From any PC within my domain, I can connect to the SQL server on the first Hyper-V service using the ODBC or the connection string file
(.UDL), BUT not through the “visual studio express 2012 web” !!!!!!!!!
Now, I can connect from any PC (using visual studio express 2012 web) to any SQL server Express 2012 on the second Hyper-V .
I have made 4 virtual service on the first hyperV and 4 on the second HyperV. All with the same result:
VS on PC’s can connect normally to any SQL server on the second HyperV
VS on PC’s can NOT connect to any SQL server on the first HyperV
VS on virtual servers on first HyperV can connect normally to any SQL server on the same physical machine/Same hyperV .
VS on virtual servers on first HyperV can connect normally to any SQL server on the second physical machine/Second hyperV .
VS on virtual servers on the second HyperV can connect to any SQL server on PC’s or on the second HyperV/Same physical machine.
VS on virtual servers on the second HyperV can NOT connect SQL servers on the first HyperV
Long story that last more than one month
L -
Best practise for creating an application that connects to a SQL Server database
I have created an application that connects to a SQL Server database and views information using a datagrid and performs several updates when a button
is selected.
I have created a SQLcontrol.vb using the following code:
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class SQlControl
'connection 1
Public SQLCon As New SqlConnection With {.ConnectionString
= "Data Source=;Initial Catalog=;Integrated Security=True"}
'connection 2
Public SQLCon1 As New SqlConnection With {.ConnectionString
= "Data Source;Initial Catalog=;Integrated Security=True"}
Public sqlcmd As SqlCommand
Public sqlda As SqlDataAdapter
Public sqldataset As DataSet
Public Function hasconnection() As Boolean
Try
SQLCon.open()
SQLCon.close()
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
Public Sub runquery(query As String)
Try
SQLCon.Open()
sqlcmd = New SqlCommand(query,
SQLCon)
'LOAD
SQL RECORDS FOR DATAGROD
sqlda = New SqlDataAdapter(sqlcmd)
sqldataset = New DataSet
sqlda.Fill(sqldataset)
BH READ DIRECTLY FROM THE DATABASE
'Dim
R As SqlDataReader = sqlcmd.ExecuteReader
'While
R.Read
'MsgBox(R.GetName(0)
& ": " & R(0))
'End
While
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
'will
close connection if still open
If SQLCon.State
= ConnectionState.Open Then
SQLCon.Close()
End If
End Try
End Sub
Public Sub runquery1(query As String)
Try
SQLCon1.Open()
sqlcmd = New SqlCommand(query,
SQLCon1)
'LOAD
SQL RECORDS FOR DATAGROD
sqlda = New SqlDataAdapter(sqlcmd)
sqldataset = New DataSet
sqlda.Fill(sqldataset)
BH READ DIRECTLY FROM THE DATABASE
'Dim
R As SqlDataReader = sqlcmd.ExecuteReader
'While
R.Read
'MsgBox(R.GetName(0)
& ": " & R(0))
'End
While
SQLCon1.Close()
Catch ex As Exception
MsgBox(ex.Message)
'will
close connection if still open
If SQLCon1.State
= ConnectionState.Open Then
SQLCon1.Close()
End If
End Try
End Sub
End Class
A code for one of my button which views displays data grid contains the following code:
Private Sub Button1_Click_1(sender As Object,
e As EventArgs) Handles Button1.Click
If SQL.hasconnection
= True Then
SQL.runquery("select
* from tablea")
If SQL.sqldataset.Tables.Count
> 0 Then
DGVData.DataSource = SQL.sqldataset.Tables(0)
End If
End If
End Sub
I am fairly new to vb.net and have read a few books and followed a few tutorials on youtube, what I would like to know is, are there any disadvantages
to the way I have connected to a SQL database using the SQLControl.vb. A lot of the vb books include data adapter and dataset within the form, I'm not sure if I'm following best practice by have the connection details outside of the form.
My other question is, I have created two connections in the SQLControl and call these connections within the same form using the same data adapter
and dataset. It all works fine but I just wanted to know of any potential issues?
Public SQLCon As New SqlConnection With {.ConnectionString
= "Data Source=;Initial Catalog=;Integrated Security=True"}
'connection 2
Public SQLCon1 As New SqlConnection With {.ConnectionString
= "Data Source;Initial Catalog=;Integrated Security=True"}
ThanksMy other question is, I have created two connections in the SQLControl and call these connections within the same form using the same data adapter and dataset. It all works fine but
I just wanted to know of any potential issues
1) You are not using Sepration of concerns for a solution that is doing data access, like using a DAL.
http://en.wikipedia.org/wiki/Separation_of_concerns
2) You are directly issuing SQL commands at the UI, leading to sql injection attacks.
3) You are not using a UI design pattern, which leads you to tightly couple database activity to the UI.
http://www.codeproject.com/Articles/228214/Understanding-Basics-of-UI-Design-Pattern-MVC-MVP
@System243trd, parameters are important to prevent SQL injection attacks (people will insert SQL commands into the database if you do not perform basic checking of what you are passing to the database). If you write a stored procedure try to make
the variables the correct SQL server data type to avoid problems later of people trying to call it directly. Darnold924 is right, I see no code to prevent against SQL injection attacks. In addition, during development in some instances LocalSQLDB
database system is used and during deployment you usually need to use the production SQL server database. Moreover, Linq-to-SQL is used on Windows Phone 8.1 and it is required for phone development later and so I highly recommend learning
it if you plan on developing windows phone applications.
@System243trd, If you want the code for the windows phone app I think it uses the MVVM model or that might be for universal apps or regular windows phone apps. I have been using the windows phone Silverlight pivot or panorama template (it might
be pieces of both). I've already submitted to the windows phone marketplace and it had to go through certification first. I plan on later making an article on it but I need to first fix one or two simple problems I have with it. Here's a link to
the source code if you later want to look at the source code (in vb.net):
https://jeffsblogcodesamples.codeplex.com/downloads/get/1445836
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - Sherlock Holmes. speak softly and carry a big stick - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog
- http://www.computerprofessions.us -
Cant export worksheet when connected to MS SQL Server 2000
SQL Developer version: 1.5.1
Hello,
I have a connection to an SQL Server 2000 database. I can select data with an "order by" clause but I receive an error when I attempt to do an "Export --> xls" on the worksheet data. I dont think this was a problem prior to SQL Developer 1.5.
No export error occurs if the "order by" cluase is removed.
Here is an example of a select stmt that generates the error.
select LastName, FirstName, EmployeeID
from northwind.dbo.employees
order by LastName, FirstName
Here are the error details:
First dialog box error text: The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.
Second dialog box error text (after clicking Details button):
java.lang.NullPointerException
at oracle.dbtools.raptor.dialogs.export.ColumnPanel.addColumnsToTree(ColumnPanel.java:85)
at oracle.dbtools.raptor.dialogs.export.ColumnPanel.showPanel(ColumnPanel.java:61)
at oracle.dbtools.raptor.dialogs.export.ColumnPanel.<init>(ColumnPanel.java:45)
at oracle.dbtools.raptor.dialogs.actions.TableExportAction.showPanels(TableExportAction.java:297)
at oracle.dbtools.raptor.dialogs.actions.TableExportAction.launchDlg(TableExportAction.java:197)
at oracle.dbtools.raptor.format.ui.ExportContextMenuListener$1.actionPerformed(ExportContextMenuListener.java:137)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
The table selected from is not a view, inline function, derived table, or subquery (as the error suggests). I can work around the problem by adding "TOP nnnn" to the select statement but this shouldn't be required.
Any suggestions?
Thanks.I confirmed that this is not a problem in SQL Developer 1.2.1.32.13. It started with 1.5. In 1.5.1.5540 I can successfully run the query and see the output in the Results tab. Only the Export has the error.
-
Error Deploying Web application that Connects to MS SQL Server
Hello I have Created a data Source that connects to a SQL Server Database and its conecting but whenever i try running the web server that contains a web page that accesses a Datasource (Microsoft) I get this error
Exception is: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.microsoft.sqlserver.jdbc.SQLServerDriver
06/04/26 12:26:37 SEVERE: ApplicationStateRunning.initConnector Stack trace: oracle.oc4j.sql.DataSourceException: Exception creating connection pool. Exception: oracle.oc4j.sql.config.DataSourceConfigException: Unable to create : com.microsoft.sqlserver.jdbc.SQLServerDriver
at com.evermind.server.ApplicationStateRunning.initDataSourceConnectionPool(ApplicationStateRunning.java:2016)
Even though I chose the option to Upload the library with the deployment, Do i have to manually load the SQL Server Librarieswith com.microsoft.sqlserver.jdbc.SQLServerDataSource it does'nt get created.. with com.microsoft.sqlserver.jdbc.SQLServerDriver it does get created
-
I don't know how to connect (string connection) to a SQL Server 2005 db from NetBeans. I'm posting some of the database properties taken from SQL Server Management Studio Express:
Database master
Spid 52
Server name ACER-1155CCFAC6/NetSDK
Instance name NETSDK
How is the connection string in this case?This information is useless.
http://www.google.co.uk/search?hl=en&q=connect+to+mysql+db+java+example&btnG=Search&meta=
http://zamov.online.fr/EXHTML/JAVA/JAVA_376038.html
if you're still having trouble post the code you tried so that we can at least see that you've amde an effort. -
JDBC connection to Microsoft SQL Server
How connect to MS SQL 2000 using JDBC from Oracle(java stored procedure) ?
I can connect to Oracle jdbc:
create or replace and compile java source named Hello as
import oracle.jdbc.driver.OracleDriver;
(C:\oracle\bise1\db\jdbc\lib\classes12.zip\oracle\jdbc\driver)
But I don't know how to connect to
Microsoft sql server?
sorry answer in
Re: Querying MS SQL Server from PL/SQL with JDBC
1)download
Microsoft SQL Server 2005 JDBC Driver 1.2
2)C:\oracle9i\bin>loadjava -user scott/tiger sqljdbc.jar
import com.microsoft.sqlserver.jdbc.SQLServerDriver;Hello,
SQL Server Express will go to sleep if idle, this behavior is not configurable.
When SQL Express transitions from idle to active some of the memory that was released needs to be reclaimed; this results is a slight lag during "startup time" when you're first connecting to SQL Express.
The other sort of sleep occurs when a database with AUTO_CLOSE unloading itself after a period of inactivity. This can be resolved by setting AUTO_CLOSE to false.
You can refer to the following blog about more details about this:
http://blogs.msdn.com/b/sqlexpress/archive/2008/02/22/sql-express-behaviors-idle-time-resources-usage-auto-close-and-user-instances.aspx
You can try to upgrade the SQL Server Express to a non-free version to get rid of this.
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support -
Connecting to MS SQL Server on UNIX/LINUX
Hello friends,
Is there a driver available to connect to MS SQL Server from a java application or servlet running on UNIX or Linux box?
Is there a way to create ODBC connection to it on UNIX?
Thank you!Is there a driver available to connect to MS SQL Server from a java application or servlet running on UNIX or Linux box? Quite probably. Go here to find out:
http://industry.java.sun.com/products/jdbc/drivers
Is there a way to create ODBC connection to it on UNIX?I've heard something about a Unix ODBC simulator, but I wouldn't bother with that. ODBC is not necessary in this situation. -
Connection with Microsoft SQL Server version 7/2000
Hello,
I am a VB expert, but new in Oracle forms by starting from 6i.
I am trying to get connected from oracle forms to Microsoft SQL server to get some data as batch job.
Is some body can help me connecting to MS SQL Server, please.Hi,
Create the odbc data source of SQL Server database and then while connecting through the Forms in the connection string write UserName/Password and host string as odbc:<odbc_Name>.
Hope this will work.
Regards
gaurav -
How do I create a connection string to sql server?
Hi All,
I am currently connecting to a SQL Server via ODBC DSN connection. I am wondering how do I create a connection string directly to a sql server without a DSN connection?
Thank you in advance.If you have SQL Server or client installed in your machine you can directly connect to SQL server using native connection. When you create new report you can see the option create new connection, here you can see SQL Server. Expand it and enter the connection details where you will be directly connected to SQL Server without ODBC connection.
Regards,
Raghavendra
Maybe you are looking for
-
Search help (PREM) for personal no. is not coming in ALV grid table control
hi experts, Search help (PREM) for personal no. is not coming in ALV grid table control. i have assigned the srch help (prem) to my 'ZFIEXP_PROJALLOC' table for the emp_id. but in output it is now showing the help. ls_fcat-fieldname = 'EMPLOYEE CODE'
-
Using SharePlus application in the Enterprise
Using a SharePoint deployment for content and collaboration, we needed a way to intuitively interact with this environment on the iPad. Using an application called SharePlus we were able to do this. We had issues with using client certificates on the
-
How to search for all files w Metadata mismatch?
I Upgraded recently from LR2.6 to 3.3. Many of my images have an Exclamation Mark on them, following the upgrade, informing me that there is a Metadata Mismatch... When I click on it I get this Dialogue box: Firstly I think LR developers are playing
-
Refresh a graph programmatically
Hi I'm trying to capture a screenshot af XY graph and print it to a PNG file. I'm using Write PNG file to print the image which I grab using theget image invoke node. My VI is split inot three frames. Frame 1 - display VI on the graph Frame 2 - Mo
-
Question on Using Safari on Admin Acct vs. Standard Acct
Quick Safari question from a long time experienced PC guy who has just switched for the first time. I am running v10.5.4 on a new iMac and have just started getting acclimated to Safari (v3.1.2) as I've been an exclusive FF user on Windows for years