Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

JDBC Connection code to connect servlet with SQL Server 2008

Ads

 
 

Share on Google+Share on Google+

Trushna
JDBC Connection code to connect servlet with SQL Server 2008
1 Answer(s)      5 years ago
Posted in : JSP-Servlet

Please ans me why it is not connect i use netbeans IDE7.0 Jdk 1.7 i also add sqljdbc4.jar but the output is SEVERE: Java Runtime Environment (JRE) version 1.6 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0. i try Avery thing but i m not success so please ans me .
My connection code is

static Connection con; static Statement st; static PreparedStatement ps; static final String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; static final String url = "jdbc:sqlserver://localhost=127.0.0.1:1433;databaseName=JSPPROJECT;selectMethod=cursor"; //localhost=127.0.0.1 //static String url ="jdbc.mssql:192.168.1.99:8080/Test"; static String userName ="sa"; static String password ="1309";

public MyDBConnection1() {
}


public static void getConnection(String InvoiceNo , String FirstName, String LastName, String CourseName, String BatchTime)
{
    try {
        try {
            Class.forName(driver);
        } 
        catch (ClassNotFoundException ex) 
        {
            ex.printStackTrace();
        }
        con = DriverManager.getConnection(url,userName,password);
        System.out.println("---connection establised ------"+con.toString());
        st=con.createStatement();
        String query = " insert into StudentDetails(InvoiceNo,FirstName,LastName,CourseName,BatchTime) values (InvoiceNo,FirstName,LastName,CourseName,BatchTime) ";
        //String query = " insert into StudentDetails(InvoiceNo,FirstName,LastName,CourseName,BatchTime) values (ivno,fname,lname,cname,btime) ";

        //ps = con.prepareStatement("insert into StudentInfo(studentId,studentName,studentAddress) values (?,?,?) ");
        //ps.setString(1, studentId);

        int record = st.executeUpdate(query);
        System.out.println(" Inserted Records :"+record);

    } 
    catch (SQLException ex) 
    {
        ex.printStackTrace();
    }
    finally 
    {
        try 
        {
            if(con!=null)
            {
                con.close();
            }
        }
        catch (SQLException ex) 
        {
            ex.printStackTrace();
        }
    }
}

public static void main(String args[])
{
    getConnection(driver, userName, userName, userName, userName);
}

}

Ads
View Answers

January 3, 2013 at 5:43 AM


remove sqljdbc.jar


Ads









Related Tutorials/Questions & Answers:
JDBC Connection code to connect servlet with SQL Server 2008
JDBC Connection code to connect servlet with SQL Server 2008  Please ans me why it is not connect i use netbeans IDE7.0 Jdk 1.7 i also add... connection code is static Connection con; static Statement st; static
JDBC Connection code to connect servlet with oracle.
JDBC Connection code to connect servlet with oracle.  JDBC Connection code to connect servlet with oracle
Advertisements
SQL SERVER 2008
SQL SERVER 2008  when i am fill the all fields in the form.but when i am retrive from the database it shows only firstname,age,address.remaining fields was shows as null.and it shows the gender as the on.i can't understand what
Sql Server 2008 with textbox
Sql Server 2008 with textbox  **Hi, I tried to insert into DB using... for user 'sa'] i tried to get a solution for this error this the code i used... myconn = New SqlConnection("server=localhost;" & "Initial Catalog=4
Database connection sql server 2005 - JDBC
Database connection sql server 2005  Hi all i am developing an application in struts and i need to connect database for that application using sql server 2005.. can anyone tell me how to make database connection ..plz help me
Server DB connection - JDBC
Server DB connection  Hello Guys I want to connect two databases... get it to work. If you have any sample code for getting connection please.... One database is on my localhost and the other one is on server, I want
could not connect to the server - JDBC
: Connection timed out: connect STACKTRACE: java.net.SocketException: java.net.ConnectException: Connection timed out: connect...could not connect to the server  Hii sir, I am working with a JBDC
JDBC connection and SQL Query - JDBC
JDBC connection and SQL Query  Hi, I'm reading a all files one after the other in a directory in java. storing the values in an array of string... to make it. even the code i wrote below has some error with quotation marks
Error while SQL Server connection to Java
Error while SQL Server connection to Java  import java.sql.*; public..."); con=DriverManager.getConnection("jdbc:odbc:SQL_SERVER;user=DTHOTA;password...("password", " "); con=DriverManager.getConnection("jdbc:odbc:SQL_SERVER", prop
Error while SQL Server connection to Java
Error while SQL Server connection to Java  import java.sql.*; public..."); con=DriverManager.getConnection("jdbc:odbc:SQL_SERVER;user=DTHOTA;password...("password", " "); con=DriverManager.getConnection("jdbc:odbc:SQL_SERVER", prop
connect sql server 2005 using php
connect sql server 2005 using php  how to connect sql server 2005 using php program. how mssql_connect will work
how to connect SQL Server 2005 using php
how to connect SQL Server 2005 using php  i need to connect SQL Server 2005 using php. how can i connect . how to use mssql_connect function
server database connection - JSP-Servlet
server database connection  sir generally we will connect..."); 2.Connection con=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft ODBC For Oracle}","scott","tiger"); But how to get the connection from
jdbc odbc sql server exception
jdbc odbc sql server exception  Hi, I am trying to use sql server with java jdbc odbc but I am getting this exception java.sql.SQLException: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near [email protected]
can't connect to MySQL Server(10060) - JDBC
can't connect to MySQL Server(10060)  Hii Sir, I am working with a jsp project with MySQL as server. Now i want to host my application. I am... MySQL front end. Can we connect to the MySQL server using the I.P address
unable to connect to server - JSP-Servlet
unable to connect to server  thank you for the program code...-application-server/tomcat/install-configure.shtml Here you will get step by step installation and configuration of Apache Tomcat Server. After installation
jdbc connection to java program code - JDBC
jdbc connection to java program code  i want a simple java program that which communicates with oracle database like creating table,insert values and update records in database and show in program output? please take a simple
Java servlet with jsp on sql server
Java servlet with jsp on sql server  How to delete a user by an admin with check box in Java Servlet with jsp on Sql Server?   Here... checkbox.In the given code, we have specified only three fields bookid,author
code for jsp to db connection using jdbc
code for jsp to db connection using jdbc  please send me the code   Hi Friend, Try the following code: 1)form.html: <html> <...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc
JDBC connection
to understand JDBC connection. The code explains you   how... Jdbc Connection, We have a list of method required to connect and close... JDBC connection       The JDBC
Sql Connection is not creating
Sql Connection is not creating  Hi i am developing an web application..for that i am using excel as database. To connect for database am using jdbc... it is creating sql connection and allwoing me to access excel but when i am
DataBase connection with sql - Struts
DataBase connection with sql  How to connect sql and send db error in struts? what are the tag should i code in struts-confic.xml
database connection - SQL
database connection  hi friends, This is poornima i want to connect sql server to my eclipse editer how to connect and where i have to write code...-database connection in eclipse IDE? Thanks
how to connect mysql with JDBC - JDBC
in the database MYsql, i have to connect them now using JDBC, can u please suggest me... { connection = DriverManager.getConnection("jdbc:mysql://localhost...(); } } Thanks Rajanikant  Hi friend, To mysql connect using JDBC
connection - JDBC
connection  how to connect server pages to mysql  Hi Friend, To learn how to connect MySql to JSP, please visit the following link: http://www.roseindia.net/jsp/connect-jsp-mysql.shtml Thanks
SQL connection error in android
SQL connection error in android  hi, i am android developer . recently i made one application connect with sql server 2005 using jtds...:sql:Exception : BUFFERDIR connection property invalid. if you have any answer
PHP SQL close connection
PHP SQL close connection       PHP SQL close connection is used to close a connection between the PHP... 'PHP SQL close Connection'. To understand and grasp the example we include
how can i create a mysql database to connect to this code - JDBC
"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
how can i create a mysql database to connect to this code - JDBC
"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
java and sql server NOT Mysql - JSP-Servlet
java and sql server NOT Mysql  Hi guys. Thank you all... was not properly answered. What I wanted was JSP CODE that can insert and retrieve image from MS SQL server NOT MySQL. Or is it not possible to do it in MS SQL server
JDBC Connection Pool
database connection in resource pool. You can make your own code for JDBC... database connection and executing the SQL statements Benefits of JDBC Connection...JDBC Connection Pool In this section we will learn about JDBC Connection Pool