dear friends
I have made connection with SQLSERVER where the following
code is compiling properly but giving error at the runtime .
I think error in this line where i am sending the value
through string
Connection connection = DriverManager.getConnection
( "jdbc:microsoft:sqlserver://localhost:1433","sa","");
import java.sql.*;
//import mssqlserver.*;
public class TestSQLCON
{
public TestSQLCON() throws Exception
{
// Get connection
DriverManager.registerDriver(new
com.microsoft.jdbc.sqlserver.SQLServerDriver());
System.out.println();
System.out.println("Successfully connected one");
System.out.println();
Connection connection = DriverManager.getConnection
( "jdbc:microsoft:sqlserver://localhost:1433","sa","");
if (connection != null)
{
System.out.println();
System.out.println("Successfully connected");
System.out.println();
// Meta data
DatabaseMetaData meta = connection.getMetaData();
System.out.println("\nDriver Information");
System.out.println("Driver Name: " +
meta.getDriverName());
System.out.println("Driver Version: " +
meta.getDriverVersion());
System.out.println("\nDatabase Information ");
System.out.println("Database Name: " +
meta.getDatabaseProductName());
System.out.println("Database Version: "+
meta.getDatabaseProductVersion());
}
}
public static void main (String args[]) throws Exception
{
TestSQLCON test = new TestSQLCON();
}
}
so please help me
Answers were Sorted based on User's Feedback
Answer / cheemu
Looks like you forgot to mention the database name in your
database URL
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / ignatiuesarun
jdbc:sqlserver://SERVERNAME(\\SQLEXPRESS):(port);databaseName=dbname;user=sa;password=***;
Just try this code, I hope it will help, make sure it
whether TCP/IP listening the default port 1433 or
not,otherwise, you have to give the correct TCP dynamic
port, you can get it from
start->programs->MicrosoftSqlServer2005->configuration
tools->Sqlserver configuration manager->expand SqlServer2005
Network configuration->(click)Protocols for SqlExpress->(on
right hand side)make surec it TCP/IP enabled and right click
on it->properties->TCP dynamic port(this is port no here
your machine TCP/IP listen)
Is This Answer Correct ? | 0 Yes | 0 No |
What is JDBC Driver interface?
Is jdbc open source?
How can I write to the log used by DriverManager and JDBC drivers?
What is hbm xml?
What type of driver you use in real-time projects?
What is Normalization?
2 Answers Accenture, Atos Origin,
What is the exception thrown by JDBC ?
Is java a database?
What do you mean by batch processing in jdbc?
What is a lock in jdbc?
MY code is: public class P1{ public static void main(String ar[]) { class.forName("java.lang.String"); } } errors i got are :New.java:5: error: <identifier> expected class.forName("java.lang.String"); ^ New.java:5: error: invalid method declaration; return type required class.forName("java.lang.String"); ^ New.java:5: error: illegal start of type class.forName("java.lang.String"); ^ New.java:7: error: reached end of file while parsing } ^ 4 errors HELP ME>......
What is jdbc driver manager?