Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTDS connection string problem

843840Mar 10 2008
Hi all i am using currently jtds sql server driver for connection so in lan i am accessing database from server so following is working properly



//dbaseConnection.java,a java bean class illustrating the SQLServer database connection

package com.base.urna.util.database;
import java.sql.Connection; //connection interface
import java.sql.Statement; // Statement interface
import java.sql.DriverManager; // DriverManager class
import java.sql.ResultSet; // ResultSet interface
import java.sql.ResultSetMetaData;
import java.sql.DatabaseMetaData; // ResultSetMetaData interface
import java.sql.SQLException; // SqlException interface


/**
* @author abhinay
* database connection
*/


public class SQLServerConnection
{

Connection connection=null;
Statement statement=null;
static final private String jdbc_driver="net.sourceforge.jtds.jdbc.Driver";

static final private String dBase_url="jdbc:jtds:sqlserver://baseserver:1433/BASE_URNA;selectMethod=cursor";



public SQLServerConnection()
{
connection=null;
statement=null;
} // default constructor of the connection class

public void setConnection()
{

try
{

Class.forName(jdbc_driver).newInstance(); // static method of class Class



connection=DriverManager.getConnection(dBase_url,"baserf","rf"); //It returns an interface which is used

throughout the application


statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); // a

statement object is created.

//CreatStatement() takes two arguments-1st arg specifies type of scrolling(values:TYPE_SCROLL_SENSITIVE &

TYPE_SCROLL_INSENSITIVE)
// and the 2nd arg specifies whether the resultset is read only or updatable(values:CONCUR_READ_ONLY &

CONCUR_UPDATABLE)


}
catch(Exception e) // Exception is used instead of SQLException because static

method forName() throws java.lang.ClassNotFoundException.

{ System.out.println(e.getMessage());}
}

public Connection getConnection() // getter methods
{
setConnection();
return connection;
}
public Statement getStatement()
{
setConnection();
return statement;
}

public void closeResources() // Releases the resources
{
try
{
statement.close();
connection.close();
}
catch(SQLException se)
{
System.out.print("\nException: " + se.getMessage() + " Error: " + se.getErrorCode() );
se.printStackTrace();
}
catch(Exception e)
{
System.err.print(e.toString() );
e.printStackTrace();
}
}
} // End of java bean class.

So through server i am running my application is working but actully i want to access local machine also so connection string i am using for local machine is :
static final private String dBase_url="jdbc:jtds:sqlserver://localhost:1433/BASE_URNA;selectMethod=cursor";

connection=DriverManager.getConnection(dBase_url,"","");
But that code is throwing null pointer exception please tell me how to solve these problem thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2008
Added on Mar 10 2008
0 comments
493 views