When I try something like this:
Class.forName("com.mysql.jdbc.Driver").newInstance();
DriverManager.getConnection("jdbc:mysql://192.168.2.116:3306/SocialFamilyTree");
I get an error:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Tried:
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
DriverManager.getConnection("jdbc:sqlserver://localhost:1433");
}catch(Exception e){
System.out.println("Couldn't get database connection.");
e.printStackTrace();
}
and got:
Couldn't get database connection.
Oct 06, 2012 11:15:37 PM com.microsoft.sqlserver.jdbc.SQLServerConnection <init>
if you are trying to connect to sql server your code is wrong , as in that you are trying to connect to mysql .
Use jtds or sql server driver to connect
Microsoft SQL Server 2005 JDBC Driver
DRIVER CLASS: com.microsoft.sqlserver.jdbc.SQLServerDriver
DRIVER LOCATION: Specify the location on your machine of the Microsoft SQL Server driver. See your Microsoft SQL Server driver documentation for more details. Certain versions of the Microsoft SQL Server driver require more than one jar file for the driver location. In this case, simply separate each file location by a semi-colon.
JDBC URL FORMAT: jdbc:sqlserver://<server_name>:<port>
The default port for Microsoft SQL Server is 1433. Usually, if the default port is being used by the database server, the : value of the JDBC url can be omitted.
Examples:
jdbc:sqlserver://neptune.acme.com:1433
jdbc:sqlserver://127.0.0.1:1433
Related
I have installed SQL Server 2014 in Windows 10 with database port (1433) instead of a named instance with Java8. I am trying to use the below mentioned connection string format to connect.
jdbc:sqlserver://localhost:1433;databaseName=TEST_DATABASE;userName=user;password=user
But the connection fails. The SQL JDBC driver I am using is sqljdbc42.jar. I am able to connect successfully while trying to SQL server created using instance name instead of port. The format mentioned below works fine.
jdbc:sqlserver://localhost;instanceName=COMP_SYS;databaseName=NEW_DATABASE;userName=user;password=user
Only with DB port connection is getting failed. What am I missing.
This is error stack trace i am getting...
Could not connect to mydb.
Error creating SQL Model Connection connection to mydb. (Error: oracle.jdbc.OracleDriver)
oracle.jdbc.OracleDriver
Error creating JDBC Connection connection to mydb. (Error: oracle.jdbc.OracleDriver)
oracle.jdbc.OracleDriver.
I am using oracle thin driver to connect to database..
SID: db
Host: localhost
Port number 1521
User name: system
Password:
Connection URL: jdbc:oraclethin:©lccalhost:1521:db
I can't even able to ping the database...
There is a typo in your connection URL. It says lccalhost instead of localhost. Try:
jdbc:oraclethin:©localhost:1521:db
Furthermore, your log says mydb instead of db as stated in your connection settings. So, this may be another possible cause of fault.
I think you are using xpress edition 11-g and if so then try changing the SID from db to xe and then it should work fine .
If you are using the standard edition then you must check with the odbc jars .
Try adding odbc6 jar
I'm trying to connect to a sql server with JDBC in java.
My server uses a windows authentication.
I use this code:
String url = "jdbc:sqlserver://MYPC\\MYSERVER;databaseName=MYDB;integratedSecurity=true";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url);
In my classpath i have the file:
jtds-1.3.1.jar and sqljdbc4.jar
And i have a VM argument:
-Djava.library.path="SQLPATH\jtds\x64\SSO"
When i run the code, i have this exception:
com.microsoft.sqlserver.jdbc.SQLServerException: Unable to connect to the host MYPC
Do you know what is wrong?
The URL syntax is jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
Did you try to ping your host using ping command ? Or try with IP address.
If //MYPC\\MYSERVER is a network path, I'd imagine it needs to look like this:
\\MYPC\\MYSERVER
Of course, if the SQL Server 2008 instance is setup as the default instance, the \\MYSERVER portion isn't necessary.
How do we connect to MS SQL 2008 server win jdk 1.6?
When I connect it via netbeans
url = jdbc:sqlserver://192.168.0.4:1434;databaseName=pollbooth
or
url = jdbc:sqlserver://192.168.0.4:1434/pollbooth
when ever I already properly configure MS SQl driver, sqljdbc.jar & sqljdbc4.jar, it sends
can't establish a connection to given url using
com.microsoft.sqlserver.jdbc.SQLServerDriver(JRE).
The following link will help you in connecting to the MSSQL Server database.
http://msdn.microsoft.com/en-us/library/ms378428(v=sql.90).aspx
I am new to eclipse.Can anybody help?
how to write connection string (url) in eclipse for jtds to connect to Sql server 2008R2 ?
driverClassName=net.sourceforge.jtds.jdbc.Driver
url=jdbc:jtds:sqlserver://localhost;databaseName=yourDB
duplicated a few other times :
Help me create a jTDS connection string
What is the jTDS JDBC Connect URL to MS SQL Server 2005 Express