JDBC Connection code to connect servlet with SQL Server 2008

Ads
 

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 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);
}

}

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
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
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 '@P1
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
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
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
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
servlet-jdbc
. 5)Your DSN will get created. 6) Compile your servlet and restart the server and run your servlet. Here is your required servlet code: import java.io.... = "jdbc:odbc:student"; Connection connection; try{ String username
jdbc connection
"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1...jdbc connection  How to Submit data????   <%-- view... { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection
JDBC connection timeout
The code include a class JDBC Connection Timeout, inside the main method we include... JDBC connection timeout       The Tutorial describe you a JDBC Connection timeout. In this program, we
jdbc connection issues
in the database correspondingly. How pls tell me how connect these 11 forms and 11 tables with only one jdbc connection program...if possiable pls post a sample code...jdbc connection issues  Hello. kindly pls help in this issue...i
JDBC-SERVLET
JDBC-SERVLET  while doing JDBC connectivity with servlet my driver is getting load but its giving exception for connection that DSN name not found...://www.devmanuals.com/tutorials/java/servlet/ConnectDb.html Thanks
JDBC connection
JDBC connection  ![alt text][1]I got exception in Connecting to a MySQL Database in Java. The exception is ClassNotFoundException:com.mysql.jdbc.Driver wat is the problem
sql php code
sql php code       SQL PHP code executes the statement using the mysql_query ( ) function... and elaborate the example we have a PHP server scripting code that includes host, user
JDBC ODBC Connection In Java
is sun.jdbc.odbc.JdbcOdbcDriver. JDBC ODBC Connection To Connect the JDBC and ODBC...JDBC ODBC Connection In Java In this section we will read about the various aspects of JDBC ODBC such as, JDBC-ODBC bridge, JDBC ODBC connection, how
Java Connect to and FTP Server
Java Connect to and FTP Server  What is the code for Java Connect to and FTP Server? How to establish a connection to FTP server in Java? Thansk... the apache commons library to connect/login to FTP server. Link of complete example
JDBC-SERVLET
JDBC-SERVLET  *while doing connectivity of jdbc with servlet I m.... ***********My code is******** <html> <body> <form action="servlet...; </html> ***************java code*************** import java.io.
Jdbc Mysql Connection Url
JDBC Mysql Connection Url       The Tutorial want to illustrate a code that explain you to understand JDBC Mysql Connection. In this program, the code explain the JDBC url and string
JDBC Connection and Registration
JDBC Connection and Registration   How to create a JDBC connection... your java with jdbc code.. It will create table in MS access database. Here..... :-)   JDBC MS Access Database Connectivity: Follow these steps: 1)Go
REQ for connection b/w jdbc and oracle database
REQ for connection b/w jdbc and oracle database    REQ for connection b/w jdbc and oracle database    The Java classes to connect... (OCI or Thin) through the JDBC connection URL. Here are some connection URL
retriving data from sql server using jsp code and placing them in text fields of html code
retriving data from sql server using jsp code and placing them in text fields... server 2008 using a jsp file and place the values in the text fields of a html file..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database... is Weblogic 8. Which is the best approach to create a connection pool? ...{ public static void main(String[] args){ Connection con = null; String url
sql-jdbc
sql-jdbc  how to execute select query using prepared statement
jdbc code
oracle.jdbc.driver.OracleDriver()); Connection con=DriverManager.getConnection("jdbc:oracle:thin...jdbc code   import java.sql.*; import java.io.*; import java.util.*; public class CallBill { public static void main(String args[])throws

Ads