Difference between revisions of "Example java code here"

From MyWiki
Jump to: navigation, search
 
Line 1: Line 1:
 +
Sample code which connects to sql server 2012 database on ip address of 192.168.56.111<br>
 +
 +
 
<source lang="java">
 
<source lang="java">
 
import java.sql.*;
 
import java.sql.*;

Latest revision as of 11:47, 5 February 2018

Sample code which connects to sql server 2012 database on ip address of 192.168.56.111


import java.sql.*;
 
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:sqlserver://192.168.56.111:1433;databaseName=georges_database","*****","******");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from mytable");
 
while(rs.next())
System.out.println(rs.getString(1)+"  "+rs.getString(2)  );
con.close();
}catch(Exception e){ System.out.println(e);}
 
}
}