Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

insert into spesific database

 
sajeevi bangamuwage
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i have successfully connect to my SQL server.I have create tables,Insert values and also select all values & display.my server is working properly.
but i cant find where those tables r in my server.also i have created a Database in my server & i want to add those tables into that DB.How can i write codings to do that.here now i write my program.

try{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.114:1433;user=stromme;password=stromme");
Statement stmt=conn.createStatement( );

String qry="create table studentMS(stdno varchar(32),marks1 integer,marks2 integer);";
String qryi1="insert into studentMS(stdno,marks1,marks2) Values('Madhuranga',86,97);";
int no1=stmt.executeUpdate(qry);
int no2=stmt.executeUpdate(qryi1);

String qry2="select * from studentMS;";
ResultSet rs=stmt.executeQuery(qry2);
while(rs.next()){

String s=rs.getString("stdno");
int i1=rs.getInt("marks1");
int i2=rs.getInt("marks2");
System.out.println(s+" "+i1+" "+i2);
}
conn.close();
}
catch(Exception ex){
System.err.println("SQLException: " + ex.getMessage());
}

Thank you.
Sajeevi Bangamuwage.(SCJP)
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Configure your driver to connect to specific database or use "USE DBNAME"
 
sajeevi bangamuwage
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thank you very much. i get the answer.

Sajeevi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic